mirror of
https://github.com/apache/nuttx.git
synced 2026-05-18 00:34:10 +08:00
ulimit: add ulimit implementation
implement the ulimit() based on getrlimit/setrlimit function. the ulimit() function is requiredd by vsx testset Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* include/ulimit.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ULIMIT_H
|
||||
#define __INCLUDE_ULIMIT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Get limit on the size of a file, in units of 512 bytes */
|
||||
|
||||
#define UL_GETFSIZE 1
|
||||
|
||||
/* Set limit on the size of a file */
|
||||
|
||||
#define UL_SETFSIZE 2
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
long int ulimit(int cmd, long newlimit);
|
||||
|
||||
#endif /* __INCLUDE_ULIMIT_H */
|
||||
@@ -69,7 +69,8 @@ set(SRCS
|
||||
lib_getpass.c
|
||||
lib_chdir.c
|
||||
lib_fchdir.c
|
||||
lib_confstr.c)
|
||||
lib_confstr.c
|
||||
lib_ulimit.c)
|
||||
|
||||
if(NOT CONFIG_SCHED_USER_IDENTITY)
|
||||
list(
|
||||
|
||||
@@ -33,7 +33,7 @@ CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c
|
||||
CSRCS += lib_fchownat.c lib_linkat.c lib_readlinkat.c lib_symlinkat.c
|
||||
CSRCS += lib_unlinkat.c lib_usleep.c lib_getpgrp.c lib_getpgid.c
|
||||
CSRCS += lib_lockf.c lib_flock.c lib_getpass.c
|
||||
CSRCS += lib_chdir.c lib_fchdir.c lib_confstr.c
|
||||
CSRCS += lib_chdir.c lib_fchdir.c lib_confstr.c lib_ulimit.c
|
||||
|
||||
ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
||||
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/unistd/lib_ulimit.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <ulimit.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ulimit
|
||||
*
|
||||
* Description:
|
||||
* The ulimit will make calls to getrlimit() and setrlimit() to perform
|
||||
* get and set resource limits respectively.
|
||||
*
|
||||
* Returned value:
|
||||
* On success, return a non-negative value.
|
||||
* On failure, return -1 and set the errno value.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
long ulimit(int cmd, long newlimit)
|
||||
{
|
||||
long ret = ERROR;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case UL_GETFSIZE:
|
||||
{
|
||||
struct rlimit rlp;
|
||||
getrlimit(RLIMIT_FSIZE, &rlp);
|
||||
ret = rlp.rlim_cur / 512UL;
|
||||
}
|
||||
break;
|
||||
case UL_SETFSIZE:
|
||||
{
|
||||
struct rlimit rlp;
|
||||
rlp.rlim_cur = newlimit * 512UL;
|
||||
ret = setrlimit(RLIMIT_FSIZE, &rlp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
set_errno(EINVAL);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user