#include "fuse_misc.h"
#include "fuse_kernel.h"
#include "fuse_i.h"
+#include "util.h"
#include <stdio.h>
#include <stdlib.h>
*/
pthread_attr_init(&attr);
stack_size = getenv(ENVNAME_THREAD_STACK);
- if (stack_size && pthread_attr_setstacksize(&attr, atoi(stack_size)))
- fuse_log(FUSE_LOG_ERR, "fuse: invalid stack size: %s\n", stack_size);
+ if (stack_size) {
+ long size;
+
+ res = libfuse_strtol(stack_size, &size);
+ if (res)
+ fuse_log(FUSE_LOG_ERR, "fuse: invalid stack size: %s\n",
+ stack_size);
+ else if (pthread_attr_setstacksize(&attr, size))
+ fuse_log(FUSE_LOG_ERR, "fuse: could not set stack size: %ld\n",
+ size);
+ }
/* Disallow signal reception in worker threads */
sigemptyset(&newset);
#include "fuse_opt.h"
#include "fuse_misc.h"
#include "mount_util.h"
+#include "util.h"
#include <stdio.h>
#include <stdlib.h>
static int grow_pipe_to_max(int pipefd)
{
- int max;
int res;
- int maxfd;
+ long max;
+ long maxfd;
char buf[32];
maxfd = open("/proc/sys/fs/pipe-max-size", O_RDONLY);
close(maxfd);
buf[res] = '\0';
- max = atoi(buf);
+ res = libfuse_strtol(buf, &max);
+ if (res)
+ return res;
res = fcntl(pipefd, F_SETPIPE_SZ, max);
if (res < 0)
return -errno;
static unsigned int get_max_pages(void)
{
char buf[32];
- int res;
+ long res;
int fd;
+ int err;
fd = open("/proc/sys/fs/fuse/max_pages_limit", O_RDONLY);
if (fd < 0)
buf[res] = '\0';
- res = strtol(buf, NULL, 10);
- return res < 0 ? FUSE_DEFAULT_MAX_PAGES_LIMIT : res;
+ err = libfuse_strtol(buf, &res);
+ return err ? FUSE_DEFAULT_MAX_PAGES_LIMIT : res;
}
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
'fuse_lowlevel.c', 'fuse_misc.h', 'fuse_opt.c',
'fuse_signals.c', 'buffer.c', 'cuse_lowlevel.c',
'helper.c', 'modules/subdir.c', 'mount_util.c',
- 'fuse_log.c', 'compat.c' ]
+ 'fuse_log.c', 'compat.c', 'util.c', 'util.h' ]
if host_machine.system().startswith('linux')
libfuse_sources += [ 'mount.c' ]
char *fdnam, *dev;
pid_t pid, cpid;
int status;
+ int err;
fdnam = getenv("FUSE_DEV_FD");
if (fdnam) {
- char *ep;
-
- fd = strtol(fdnam, &ep, 10);
-
- if (*ep != '\0') {
+ err = libfuse_strtol(fdnam, &fd);
+ if (err) {
fuse_log(FUSE_LOG_ERR, "invalid value given in FUSE_DEV_FD\n");
return -1;
}
- if (fd < 0)
- return -1;
-
goto mount;
}
--- /dev/null
+#include <stdlib.h>
+#include <errno.h>
+
+#include "util.h"
+
+int libfuse_strtol(const char *str, long *res)
+{
+ char *endptr;
+ int base = 10;
+ long val;
+
+ errno = 0;
+
+ if (!str)
+ return -EINVAL;
+
+ val = strtol(str, &endptr, base);
+
+ if (errno)
+ return -errno;
+
+ if (endptr == str || *endptr != '\0')
+ return -EINVAL;
+
+ *res = val;
+ return 0;
+}
--- /dev/null
+int libfuse_strtol(const char *str, long *res);
#define _GNU_SOURCE /* for clone and strchrnul */
#include "fuse_config.h"
#include "mount_util.h"
+#include "util.h"
#include <stdio.h>
#include <stdlib.h>
static int lazy = 0;
static int quiet = 0;
char *commfd = NULL;
- int cfd;
+ long cfd;
const char *opts = "";
const char *type = NULL;
int setup_auto_unmount_only = 0;
goto err_out;
}
- cfd = atoi(commfd);
+ res = libfuse_strtol(commfd, &cfd);
+ if (res) {
+ fprintf(stderr,
+ "%s: invalid _FUSE_COMMFD: %s\n",
+ progname, commfd);
+ goto err_out;
+
+ }
{
struct stat statbuf;
fstat(cfd, &statbuf);
if(!S_ISSOCK(statbuf.st_mode)) {
fprintf(stderr,
- "%s: file descriptor %i is not a socket, can't send fuse fd\n",
+ "%s: file descriptor %li is not a socket, can't send fuse fd\n",
progname, cfd);
goto err_out;
}
fuseconf_path = join_paths(get_option('prefix'), get_option('sysconfdir'), 'fuse.conf')
-executable('fusermount3', ['fusermount.c', '../lib/mount_util.c'],
+executable('fusermount3', ['fusermount.c', '../lib/mount_util.c', '../lib/util.c'],
include_directories: include_dirs,
install: true,
install_dir: get_option('bindir'),