From bf6d072124a960d3b84ae39cd15c5aeca2e41c88 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 12 Jan 2017 23:16:36 +0000 Subject: Types fix, first pass --- src/daemontools-extras/s6-applyuidgid.c | 16 +++++---- src/daemontools-extras/s6-envuidgid.c | 8 ++--- src/daemontools-extras/s6-log.c | 61 +++++++++++++++++---------------- src/daemontools-extras/s6-setlock.c | 10 +++--- src/daemontools-extras/s6-setuidgid.c | 3 +- src/daemontools-extras/s6-tai64nlocal.c | 2 +- src/daemontools-extras/ucspilogd.c | 8 +++-- 7 files changed, 58 insertions(+), 50 deletions(-) (limited to 'src/daemontools-extras') diff --git a/src/daemontools-extras/s6-applyuidgid.c b/src/daemontools-extras/s6-applyuidgid.c index 31dc198..b80564f 100644 --- a/src/daemontools-extras/s6-applyuidgid.c +++ b/src/daemontools-extras/s6-applyuidgid.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -18,7 +18,8 @@ int main (int argc, char const *const *argv, char const *const *envp) { - unsigned int uid = 0, gid = 0 ; + uint64 uid = 0 ; + gid_t gid = 0 ; gid_t gids[NGROUPS_MAX] ; unsigned int gidn = (unsigned int)-1 ; int unexport = 0 ; @@ -32,17 +33,17 @@ int main (int argc, char const *const *argv, char const *const *envp) switch (opt) { case 'z' : unexport = 1 ; break ; - case 'u' : if (!uint0_scan(l.arg, &uid)) dieusage() ; break ; - case 'g' : if (!uint0_scan(l.arg, &gid)) dieusage() ; break ; + case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ; + case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ; case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ; case 'U' : { char const *x = env_get2(envp, "UID") ; if (!x) strerr_dienotset(100, "UID") ; - if (!uint0_scan(x, &uid)) strerr_dieinvalid(100, "UID") ; + if (!uint640_scan(x, &uid)) strerr_dieinvalid(100, "UID") ; x = env_get2(envp, "GID") ; if (!x) strerr_dienotset(100, "GID") ; - if (!uint0_scan(x, &gid)) strerr_dieinvalid(100, "GID") ; + if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "GID") ; x = env_get2(envp, "GIDLIST") ; if (!x) strerr_dienotset(100, "GIDLIST") ; if (!gid_scanlist(gids, NGROUPS_MAX, x, &gidn) && *x) @@ -56,11 +57,12 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (!argc) dieusage() ; + if (uid > (uint64)(uid_t)-1) strerr_dief1x(100, "uid value too big") ; if (gidn != (unsigned int)-1 && setgroups(gidn, gids) < 0) strerr_diefu1sys(111, "set supplementary group list") ; if (gid && setgid(gid) < 0) strerr_diefu1sys(111, "setgid") ; - if (uid && setuid(uid) < 0) + if (uid && setuid((uid_t)uid) < 0) strerr_diefu1sys(111, "setuid") ; if (unexport) pathexec_r(argv, envp, env_len(envp), "UID\0GID\0GIDLIST", 16) ; diff --git a/src/daemontools-extras/s6-envuidgid.c b/src/daemontools-extras/s6-envuidgid.c index 57c178f..365a862 100644 --- a/src/daemontools-extras/s6-envuidgid.c +++ b/src/daemontools-extras/s6-envuidgid.c @@ -16,9 +16,9 @@ #define USAGE "s6-envuidgid [ -i | -D defaultuid:defaultgid ] [ -u | -g | -B ] [ -n ] account prog..." #define dieusage() strerr_dieusage(100, USAGE) -static inline unsigned int scan_defaults (char const *s, uint64 *uid, gid_t *gid, unsigned int *n, gid_t *tab) +static inline size_t scan_defaults (char const *s, uint64 *uid, gid_t *gid, unsigned int *n, gid_t *tab) { - unsigned int pos = uint64_scan(s, uid) ; + size_t pos = uint64_scan(s, uid) ; if (!pos) { if (*s != ':') return 0 ; @@ -94,7 +94,7 @@ int main (int argc, char *const *argv, char const *const *envp) break ; case 3 : /* both */ { - unsigned int pos = str_chr(argv[0], ':') ; + size_t pos = str_chr(argv[0], ':') ; user = argv[0] ; if (argv[0][pos]) { @@ -136,7 +136,7 @@ int main (int argc, char *const *argv, char const *const *envp) } { - unsigned int pos = 0 ; + size_t pos = 0 ; char fmt[19 + UINT64_FMT + (NGROUPS_MAX+1) * GID_FMT] ; if (what & 1) { diff --git a/src/daemontools-extras/s6-log.c b/src/daemontools-extras/s6-log.c index 0602c66..e7133b1 100644 --- a/src/daemontools-extras/s6-log.c +++ b/src/daemontools-extras/s6-log.c @@ -103,13 +103,13 @@ typedef struct as_status_s as_status_t, *as_status_t_ref ; struct as_status_s { char const *file ; - unsigned int filelen ; + size_t filelen ; } ; typedef union actstuff_u actstuff_t, *actstuff_t_ref ; union actstuff_u { - unsigned int fd2_size ; + size_t fd2_size ; as_status_t status ; unsigned int ld ; } ; @@ -131,7 +131,7 @@ struct scriptelem_s unsigned int actlen ; } ; -typedef void inputprocfunc_t (scriptelem_t const *, unsigned int, unsigned int, unsigned int) ; +typedef void inputprocfunc_t (scriptelem_t const *, unsigned int, size_t, unsigned int) ; typedef inputprocfunc_t *inputprocfunc_t_ref ; typedef struct logdir_s logdir_t, *logdir_t_ref ; @@ -146,7 +146,7 @@ struct logdir_s uint32 n ; uint32 s ; uint32 tolerance ; - unsigned int pid ; + pid_t pid ; char const *dir ; char const *processor ; unsigned int flags ; @@ -176,7 +176,7 @@ struct logdir_s typedef struct filesize_s filesize_t, *filesize_t_ref ; struct filesize_s { - uint64 size ; + size_t size ; char name[28] ; } ; @@ -225,7 +225,7 @@ static inline int logdir_trim (logdir_t *ldp) if (n) { uint64 totalsize = 0 ; - unsigned int dirlen = str_len(ldp->dir) ; + size_t dirlen = str_len(ldp->dir) ; unsigned int i = 0 ; filesize_t blurgh[n] ; char fullname[dirlen + 29] ; @@ -281,8 +281,8 @@ static inline int logdir_trim (logdir_t *ldp) static int finish (logdir_t *ldp, char const *name, char suffix) { struct stat st ; - unsigned int dirlen = str_len(ldp->dir) ; - unsigned int namelen = str_len(name) ; + size_t dirlen = str_len(ldp->dir) ; + size_t namelen = str_len(name) ; char x[dirlen + namelen + 2] ; byte_copy(x, dirlen, ldp->dir) ; x[dirlen] = '/' ; @@ -329,7 +329,7 @@ static inline void exec_processor (logdir_t *ldp) static int rotator (logdir_t *ldp) { - unsigned int dirlen = str_len(ldp->dir) ; + size_t dirlen = str_len(ldp->dir) ; switch (ldp->rstate) { case ROTSTATE_START : @@ -414,14 +414,14 @@ static int rotator (logdir_t *ldp) ldp->rstate = ROTSTATE_RUNPROCESSOR ; case ROTSTATE_RUNPROCESSOR : { - int pid = fork() ; + pid_t pid = fork() ; if (pid < 0) { if (verbosity) strerr_warnwu2sys("fork processor for logdir ", ldp->dir) ; goto fail ; } else if (!pid) exec_processor(ldp) ; - ldp->pid = (unsigned int)pid ; + ldp->pid = pid ; tain_add_g(&ldp->deadline, &tain_infinite_relative) ; ldp->rstate = ROTSTATE_WAITPROCESSOR ; } @@ -524,13 +524,13 @@ static int rotator (logdir_t *ldp) return 0 ; } -static int logdir_write (int i, char const *s, unsigned int len) +static int logdir_write (int i, char const *s, size_t len) { logdir_t *ldp = logdirs + i ; - int r ; - unsigned int n = len ; + ssize_t r ; + size_t n = len ; { - unsigned int m = byte_rchr(s, n, '\n') ; + size_t m = byte_rchr(s, n, '\n') ; if (m < n) n = m+1 ; } r = fd_write(ldp->fd, s, n) ; @@ -563,11 +563,11 @@ static inline void rotate_or_flush (logdir_t *ldp) bufalloc_flush(&ldp->out) ; } -static inline void logdir_init (unsigned int index, uint32 s, uint32 n, uint32 tolerance, uint64 maxdirsize, tain_t const *retrytto, char const *processor, char const *name, unsigned int flags) +static inline void logdir_init (unsigned int index, uint32_t s, uint32_t n, uint32_t tolerance, uint64 maxdirsize, tain_t const *retrytto, char const *processor, char const *name, unsigned int flags) { logdir_t *ldp = logdirs + index ; struct stat st ; - unsigned int dirlen = str_len(name) ; + size_t dirlen = str_len(name) ; int r ; char x[dirlen + 11] ; ldp->s = s ; @@ -776,9 +776,9 @@ static inline void script_secondpass (char const *const *argv, scriptelem_t *scr tain_t retrytto ; unsigned int fd2_size = 200 ; unsigned int status_size = 1001 ; - uint32 s = 99999 ; - uint32 n = 10 ; - uint32 tolerance = 2000 ; + uint32_t s = 99999 ; + uint32_t n = 10 ; + uint32_t tolerance = 2000 ; uint64 maxdirsize = 0 ; char const *processor = 0 ; unsigned int sel = 0, act = 0, lidx = 0, flags = 0 ; @@ -836,7 +836,7 @@ static inline void script_secondpass (char const *const *argv, scriptelem_t *scr break ; case 'r' : { - uint32 t ; + uint32_t t ; if (!uint320_scan(*argv + 1, &t)) goto fail ; if (!tain_from_millisecs(&retrytto, t)) goto fail ; break ; @@ -901,10 +901,11 @@ static inline void script_secondpass (char const *const *argv, scriptelem_t *scr strerr_dief2x(100, "unrecognized directive: ", *argv) ; } -static void script_run (scriptelem_t const *script, unsigned int scriptlen, char const *s, unsigned int len, unsigned int gflags) +static void script_run (scriptelem_t const *script, unsigned int scriptlen, char const *s, size_t len, unsigned int gflags) { int flagselected = 1, flagacted = 0 ; - unsigned int i = 0, hlen = 0 ; + unsigned int i = 0 ; + size_t hlen = 0 ; char hstamp[32] ; char tstamp[TIMESTAMP+1] ; if (gflags & 1) @@ -971,12 +972,12 @@ static void script_run (scriptelem_t const *script, unsigned int scriptlen, char case ACTTYPE_STATUS : if (act->data.status.filelen) { - unsigned int reallen = siovec_len(v, 4) ; + size_t reallen = siovec_len(v, 4) ; if (reallen > act->data.status.filelen) siovec_trunc(v, 4, act->data.status.filelen) ; else { - register unsigned int k = act->data.status.filelen - reallen + 1 ; + register size_t k = act->data.status.filelen - reallen + 1 ; char pad[k] ; v[3].s = pad ; v[3].len = k ; @@ -1012,9 +1013,9 @@ static void prepare_to_exit (void) flagexiting = 1 ; } -static void normal_stdin (scriptelem_t const *script, unsigned int scriptlen, unsigned int linelimit, unsigned int gflags) +static void normal_stdin (scriptelem_t const *script, unsigned int scriptlen, size_t linelimit, unsigned int gflags) { - int r = sanitize_read(buffer_fill(buffer_0)) ; + ssize_t r = sanitize_read(buffer_fill(buffer_0)) ; if (r < 0) { if ((errno != EPIPE) && verbosity) strerr_warnwu1sys("read from stdin") ; @@ -1038,7 +1039,7 @@ static void normal_stdin (scriptelem_t const *script, unsigned int scriptlen, un } } -static void last_stdin (scriptelem_t const *script, unsigned int scriptlen, unsigned int linelimit, unsigned int gflags) +static void last_stdin (scriptelem_t const *script, unsigned int scriptlen, size_t linelimit, unsigned int gflags) { int cont = 1 ; while (cont) @@ -1135,9 +1136,9 @@ static inline void handle_signals (void) { int wstat ; register unsigned int i = 0 ; - register int r = wait_nohang(&wstat) ; + register pid_t r = wait_nohang(&wstat) ; if (r <= 0) break ; - for (; i < llen ; i++) if ((unsigned int)r == logdirs[i].pid) break ; + for (; i < llen ; i++) if (r == logdirs[i].pid) break ; if (i < llen) processor_died(logdirs + i, wstat) ; } break ; diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c index 15970ed..27b6b23 100644 --- a/src/daemontools-extras/s6-setlock.c +++ b/src/daemontools-extras/s6-setlock.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -56,7 +57,7 @@ int main (int argc, char const *const *argv, char const *const *envp) iopause_fd x = { .events = IOPAUSE_READ } ; tain_t deadline ; int p[2] ; - unsigned int pid ; + pid_t pid ; char c ; tain_now_g() ; tain_from_millisecs(&deadline, timeout) ; @@ -66,6 +67,7 @@ int main (int argc, char const *const *argv, char const *const *envp) x.fd = p[0] ; for (;;) { + ssize_t rr ; register int r = iopause_g(&x, 1, &deadline) ; if (r < 0) strerr_diefu1sys(111, "iopause") ; if (!r) @@ -74,9 +76,9 @@ int main (int argc, char const *const *argv, char const *const *envp) errno = ETIMEDOUT ; strerr_diefu1sys(1, "acquire lock") ; } - r = sanitize_read(fd_read(p[0], &c, 1)) ; - if (r < 0) strerr_diefu1sys(111, "read ack from helper") ; - if (r) break ; + rr = sanitize_read(fd_read(p[0], &c, 1)) ; + if (rr < 0) strerr_diefu1sys(111, "read ack from helper") ; + if (rr) break ; } if (c != '!') strerr_dief1x(111, "helper sent garbage ack") ; fd_close(p[0]) ; diff --git a/src/daemontools-extras/s6-setuidgid.c b/src/daemontools-extras/s6-setuidgid.c index 30cce8c..727696a 100644 --- a/src/daemontools-extras/s6-setuidgid.c +++ b/src/daemontools-extras/s6-setuidgid.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -11,8 +12,8 @@ int main (int argc, char *const *argv, char const *const *envp) { char const *newargv[argc + 7] ; + size_t pos ; unsigned int m = 0 ; - unsigned int pos ; PROG = "s6-setuidgid" ; if (argc < 3) dieusage() ; argv++ ; diff --git a/src/daemontools-extras/s6-tai64nlocal.c b/src/daemontools-extras/s6-tai64nlocal.c index d5af0d3..84e717a 100644 --- a/src/daemontools-extras/s6-tai64nlocal.c +++ b/src/daemontools-extras/s6-tai64nlocal.c @@ -31,7 +31,7 @@ int main (void) { char fmt[LOCALTMN_FMT+1] ; localtmn_t local ; - unsigned int len ; + size_t len ; localtmn_from_tain(&local, &a, 1) ; len = localtmn_fmt(fmt, &local) ; if (buffer_put(buffer_1, fmt, len) < 0) diff --git a/src/daemontools-extras/ucspilogd.c b/src/daemontools-extras/ucspilogd.c index 9ad739d..1f338bd 100644 --- a/src/daemontools-extras/ucspilogd.c +++ b/src/daemontools-extras/ucspilogd.c @@ -6,6 +6,7 @@ #endif #include +#include #include #include #include @@ -88,9 +89,10 @@ static CODE const facilitynames[] = #endif -static unsigned int syslog_names (char const *line) +static size_t syslog_names (char const *line) { - unsigned int fpr, i ; + size_t i ; + unsigned int fpr ; int fp ; CODE const *p = facilitynames ; @@ -157,7 +159,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } for (;;) { - unsigned int pos = 0 ; + size_t pos = 0 ; satmp.len = 0 ; { register int r = skagetlnsep(buffer_0f1, &satmp, "\n", 2) ; -- cgit v1.2.3