Welcome to little lamb

Code » slicd » commit f67bc64

Type update to skalibs 2.5.0.0

author Olivier Brunel
2017-04-01 18:33:30 UTC
committer Olivier Brunel
2017-04-01 18:33:30 UTC
parent f7d0acbb2e0901b31bc83ff9da385d151a2e7f0c

Type update to skalibs 2.5.0.0

src/extra/miniexec.c +4 -3
src/extra/setuid.c +1 -0
src/include/slicd/job.h +1 -1
src/libslicd/slicd_add_job_from_cronline.c +1 -1
src/libslicd/slicd_load.c +5 -4
src/slicd/slicd-dump.c +2 -2
src/slicd/slicd-exec.c +46 -45
src/slicd/slicd-parser.c +11 -11
src/slicd/slicd-sched.c +3 -2

diff --git a/src/extra/miniexec.c b/src/extra/miniexec.c
index e33a912..5b1a841 100644
--- a/src/extra/miniexec.c
+++ b/src/extra/miniexec.c
@@ -24,6 +24,7 @@
 
 #include <getopt.h>
 #include <skalibs/djbunix.h>
+#include <skalibs/bytestr.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/genalloc.h>
 #include <skalibs/strerr2.h>
@@ -182,10 +183,10 @@ main (int argc, char * const argv[])
                 }
             }
         }
-        for (i = 0; i < genalloc_len (int, &ga_idx); ++i)
+        for (size_t j = 0; j < genalloc_len (int, &ga_idx); ++j)
         {
-            int idx = genalloc_s (int, &ga_idx)[i];
-            unsigned int offset = (unsigned int) (intptr_t) genalloc_s (char *, &ga)[idx];
+            int idx = genalloc_s (int, &ga_idx)[j];
+            size_t offset = (size_t) (intptr_t) genalloc_s (char *, &ga)[idx];
             p = sa.s + offset;
             byte_copy (ga.s + idx * sizeof (char *), sizeof (char *), &p);
         }
diff --git a/src/extra/setuid.c b/src/extra/setuid.c
index f7ee5ad..1a240d0 100644
--- a/src/extra/setuid.c
+++ b/src/extra/setuid.c
@@ -32,6 +32,7 @@
 #include <grp.h>
 #include <unistd.h>
 #include <skalibs/djbunix.h>
+#include <skalibs/bytestr.h>
 #include <skalibs/strerr2.h>
 #include <slicd/die.h>
 
diff --git a/src/include/slicd/job.h b/src/include/slicd/job.h
index c743d4d..8dbd1be 100644
--- a/src/include/slicd/job.h
+++ b/src/include/slicd/job.h
@@ -27,7 +27,7 @@
 
 typedef struct
 {
-    unsigned int offset;
+    size_t offset;
     unsigned char bits[17];
 } slicd_job_t;
 
diff --git a/src/libslicd/slicd_add_job_from_cronline.c b/src/libslicd/slicd_add_job_from_cronline.c
index b0dd8b0..402362a 100644
--- a/src/libslicd/slicd_add_job_from_cronline.c
+++ b/src/libslicd/slicd_add_job_from_cronline.c
@@ -197,7 +197,7 @@ slicd_add_job_from_cronline (slicd_t     *slicd,
 {
     slicd_job_t j = { 0, };
     const char *s = cronline;
-    int len;
+    size_t len;
     int r;
     int i;
 
diff --git a/src/libslicd/slicd_load.c b/src/libslicd/slicd_load.c
index 20b1ec9..964c734 100644
--- a/src/libslicd/slicd_load.c
+++ b/src/libslicd/slicd_load.c
@@ -22,7 +22,7 @@
 
 #include <errno.h>
 #include <skalibs/skamisc.h>
-#include <skalibs/uint32.h>
+#include <skalibs/types.h>
 #include <skalibs/djbunix.h>
 #include <slicd/slicd.h>
 #include <slicd/job.h>
@@ -33,8 +33,9 @@ slicd_load (slicd_t *slicd, const char *file)
 {
     char buf[4];
     int fd;
-    int r;
-    uint32 len, left;
+    ssize_t r;
+    size_t len;
+    uint32_t left;
 
     if (slicd->str.len > 0 || slicd->jobs.len > 0)
         return -SLICD_ERR_NOT_EMPTY;
@@ -104,7 +105,7 @@ slicd_load (slicd_t *slicd, const char *file)
 
     /* ensure loaded data are valid */
     {
-        int i;
+        size_t i;
 
         for (i = 0; i < genalloc_len (slicd_job_t, &slicd->jobs); ++i)
         {
diff --git a/src/slicd/slicd-dump.c b/src/slicd/slicd-dump.c
index 3e8cd63..ac006d6 100644
--- a/src/slicd/slicd-dump.c
+++ b/src/slicd/slicd-dump.c
@@ -28,7 +28,7 @@
 #include <slicd/fields.h>
 #include <slicd/die.h>
 #include <skalibs/buffer.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
 #include <skalibs/genalloc.h>
 #include <skalibs/strerr2.h>
 
@@ -70,7 +70,7 @@ int
 main (int argc, char * const argv[])
 {
     PROG = "slicd-dump";
-    unsigned int i, nb;
+    size_t i, nb;
     int r;
 
     for (;;)
diff --git a/src/slicd/slicd-exec.c b/src/slicd/slicd-exec.c
index da5f5ad..b449443 100644
--- a/src/slicd/slicd-exec.c
+++ b/src/slicd/slicd-exec.c
@@ -24,8 +24,8 @@
 
 #include <getopt.h>
 #include <errno.h>
-#include <skalibs/uint.h>
-#include <skalibs/uint32.h>
+#include <unistd.h>
+#include <skalibs/types.h>
 #include <skalibs/sig.h>
 #include <skalibs/allreadwrite.h>
 #include <skalibs/djbunix.h>
@@ -62,7 +62,7 @@ struct arg
 {
     unsigned char type;
     char *str;
-    int len;
+    size_t len;
 };
 
 struct child
@@ -82,19 +82,19 @@ static int exiting = 0;
 static int looping = 1;
 static stralloc sa_in = STRALLOC_ZERO;
 static struct arg *args;
-static int len_args;
+static size_t len_args;
 static int n_args;
 
 #define ga_remove(type, ga, i)     do {         \
-    int len = (ga)->len / sizeof (type);        \
-    int c = len - (i) - 1;                      \
+    size_t len = (ga)->len / sizeof (type);     \
+    size_t c = len - (i) - 1;                   \
     if (c > 0)                                  \
         memmove (genalloc_s (type, (ga)) + (i), genalloc_s (type, (ga)) + (i) + 1, c * sizeof (type)); \
     genalloc_setlen (type, (ga), len - 1);    \
 } while (0)
 
 static void close_fd (int fd);
-static void process_line (int i_c, int fd, char *line, int len);
+static void process_line (size_t i_c, int fd, char *line, size_t len);
 
 static inline void
 start_exiting (void)
@@ -110,7 +110,7 @@ start_exiting (void)
 static void
 iop_remove_fd (int fd)
 {
-    int i;
+    size_t i;
 
     for (i = 0; i < genalloc_len (iopause_fd, &ga_iop); ++i)
     {
@@ -122,16 +122,16 @@ iop_remove_fd (int fd)
     }
 }
 
-static inline int
+static inline size_t
 get_child_from_fd (int fd)
 {
-    int i;
+    size_t i;
 
     for (i = 0; i < genalloc_len (struct child, &ga_child); ++i)
         if (genalloc_s (struct child, &ga_child)[i].fd_out == fd
                 || genalloc_s (struct child, &ga_child)[i].fd_err == fd)
             return i;
-    return -1;
+    return (size_t) -1;
 }
 
 static void
@@ -146,10 +146,10 @@ close_fd (int fd)
     else
     {
         struct child *child;
-        int i;
+        size_t i;
 
         i = get_child_from_fd (fd);
-        if (i < 0)
+        if (i == (size_t) -1)
         {
             char buf[UINT32_FMT];
             uint32 u;
@@ -177,7 +177,7 @@ close_fd (int fd)
 }
 
 static void
-new_child (char *line, int len)
+new_child (char *line, size_t len)
 {
     char buf[UINT32_FMT];
     uint32 u;
@@ -186,7 +186,7 @@ new_child (char *line, int len)
     int p_err[2];
     char c;
     pid_t pid;
-    int n;
+    size_t n;
 
     n = byte_chr (line, len, ':');
     if (n == 0 || n >= len - 1)
@@ -258,7 +258,7 @@ new_child (char *line, int len)
     {
         char * argv[n_args + 2];
         stralloc sa = STRALLOC_ZERO;
-        int i;
+        size_t i;
 
         PROG = "slicd-exec (child)";
 
@@ -386,7 +386,7 @@ new_child (char *line, int len)
 }
 
 static void
-process_line (int i_c, int fd, char *line, int len)
+process_line (size_t i_c, int fd, char *line, size_t len)
 {
     struct child *child = &genalloc_s (struct child, &ga_child)[i_c];
     char buf[UINT32_FMT];
@@ -408,8 +408,8 @@ static void
 handle_fd (int fd, int all)
 {
     stralloc *sa;
-    int i_c = 0; /* to silence warning */
-    int r;
+    size_t i_c = 0; /* to silence warning */
+    ssize_t r;
     int close = 0;
 
     if (fd == 0)
@@ -417,7 +417,7 @@ handle_fd (int fd, int all)
     else
     {
         i_c = get_child_from_fd (fd);
-        if (i_c < 0)
+        if (i_c == (size_t) -1)
         {
             char buf[UINT32_FMT];
             uint32 u;
@@ -478,20 +478,20 @@ handle_fd (int fd, int all)
 
         while (sa->len > 0)
         {
-            int l;
+            size_t rr, l;
 
-            r = byte_chr (sa->s, sa->len, '\n');
-            if (r == sa->len)
+            rr = byte_chr (sa->s, sa->len, '\n');
+            if (rr == sa->len)
                 break;
 
-            sa->s[r] = '\0';
+            sa->s[rr] = '\0';
             if (fd == 0)
-                new_child (sa->s, r);
+                new_child (sa->s, rr);
             else
-                process_line (i_c, fd, sa->s, r);
-            l = sa->len - r - 1;
+                process_line (i_c, fd, sa->s, rr);
+            l = sa->len - rr - 1;
             if (l > 0)
-                byte_copy (sa->s, l, sa->s + r + 1);
+                byte_copy (sa->s, l, sa->s + rr + 1);
             sa->len = l;
         }
 
@@ -512,24 +512,24 @@ handle_sigchld (void)
         char buf[20 + UINT32_FMT];
         uint32 u;
         int wstat;
-        int r;
-        int i;
+        pid_t pid;
+        size_t i;
 
-        r = wait_nohang (&wstat);
-        if (r < 0)
+        pid = wait_nohang (&wstat);
+        if (pid < 0)
         {
             if (errno != ECHILD)
                 strerr_warnwu1sys ("reap zombies (waitpid)");
             break;
         }
-        else if (r == 0)
+        else if (pid == 0)
             break;
 
-        u = (uint32) r;
+        u = (uint32) pid;
         buf[20 + uint32_fmt (buf + 20, u)] = '\0';
 
         for (i = 0; i < genalloc_len (struct child, &ga_child); ++i)
-            if (genalloc_s (struct child, &ga_child)[i].pid == r)
+            if (genalloc_s (struct child, &ga_child)[i].pid == pid)
                 break;
         if (i >= genalloc_len (struct child, &ga_child))
         {
@@ -604,10 +604,10 @@ handle_signals (void)
     return;
 }
 
-static int
-parse_arg (struct arg *arg, char *s, int len, int in_arg)
+static size_t
+parse_arg (struct arg *arg, char *s, size_t len, int in_arg)
 {
-    int r;
+    size_t r;
 
     r = byte_chr (s, len, '%');
     if (r >= len - 1)
@@ -756,18 +756,19 @@ main (int argc, char * const argv[])
         struct arg _args[argc];
         genalloc ga_args = GENALLOC_ZERO;
         int in_arg = 0;
-        int i;
+        size_t i;
 
         n_args = argc;
         args = _args;
-        for (i = 0; i < argc; ++i)
+        for (i = 0; i < (size_t) argc; ++i)
         {
             struct arg arg;
             char *s = argv[i];
-            int len = strlen (s);
+            size_t len = strlen (s);
+            size_t rr;
 
 again:
-            r = parse_arg (&arg, s, len, in_arg);
+            rr = parse_arg (&arg, s, len, in_arg);
 
             if (arg.type != TYPE_COMBINE && arg.type != TYPE_PARTIAL)
             {
@@ -793,12 +794,12 @@ again:
 
             genalloc_append (struct arg, &ga_args, &arg);
 
-            s += r;
-            len -= r;
+            s += rr;
+            len -= rr;
             goto again;
         }
         if (args)
-            len_args = argc;
+            len_args = (size_t) argc;
         else
         {
             args = genalloc_s (struct arg, &ga_args);
diff --git a/src/slicd/slicd-parser.c b/src/slicd/slicd-parser.c
index 3ce6537..0abd9dc 100644
--- a/src/slicd/slicd-parser.c
+++ b/src/slicd/slicd-parser.c
@@ -32,7 +32,7 @@
 #include <skalibs/direntry.h>
 #include <skalibs/allreadwrite.h>
 #include <skalibs/djbunix.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
 #include <skalibs/strerr2.h>
 #include <slicd/slicd.h>
 #include <slicd/parser.h>
@@ -77,14 +77,14 @@ static void
 do_parse (const char *user, const char *file, unsigned int *line, int eof)
 {
     char *s = sa.s;
-    int len = sa.len;
+    size_t len = sa.len;
 
     for (;;)
     {
-        int l;
+        size_t l;
         int r;
 
-        if (len <= 0 || eof == 2)
+        if (len == 0 || eof == 2)
             break;
 
         l = byte_chr (s, len, '\n');
@@ -132,11 +132,11 @@ static void
 parse_file (const char *path, const char *name, void *data)
 {
     const char *username = data;
-    int l_path = strlen (path);
-    int l_name = strlen (name);
+    size_t l_path = strlen (path);
+    size_t l_name = strlen (name);
     char buf[l_path + 1 + l_name + 1];
     int fd;
-    int r;
+    ssize_t r;
     unsigned int line = 1;
 
     if (username == userfile)
@@ -185,8 +185,8 @@ parse_file (const char *path, const char *name, void *data)
 static void
 scan_userdirs (const char *path, const char *name, void *data)
 {
-    int l_path = strlen (path);
-    int l_name = strlen (name);
+    size_t l_path = strlen (path);
+    size_t l_name = strlen (name);
     char buf[l_path + 1 + l_name + 1];
 
     byte_copy (buf, l_path, path);
@@ -334,9 +334,9 @@ main (int argc, char * const argv[])
                 case TYPE_SYSTEM:
                     if (S_ISREG (st.st_mode))
                     {
-                        int len = strlen (crontab[i].path);
+                        size_t len = strlen (crontab[i].path);
                         char buf[len + 1];
-                        int l;
+                        size_t l;
 
                         byte_copy (buf, len + 1, crontab[i].path);
 
diff --git a/src/slicd/slicd-sched.c b/src/slicd/slicd-sched.c
index ccde9c2..7e0f67b 100644
--- a/src/slicd/slicd-sched.c
+++ b/src/slicd/slicd-sched.c
@@ -25,7 +25,8 @@
 #include <getopt.h>
 #include <errno.h>
 #include <sys/timerfd.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
+#include <skalibs/bytestr.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/iopause.h>
 #include <skalibs/selfpipe.h>
@@ -206,7 +207,7 @@ main (int argc, char * const argv[])
         {
             struct tm cur_tm, next_tm, *tm;
             time_t cur_time, next_time;
-            int i;
+            size_t i;
 
             if (clock_gettime (CLOCK_REALTIME, &its.it_interval) < 0)
                 strerr_diefu1sys (RC_OTHER, "get current time");