author | Olivier Brunel
<jjk@jjacky.com> 2017-04-01 21:22:11 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2017-06-18 12:40:37 UTC |
parent | f26a94dafac7af499d065ba0c8a7386a8644e1c4 |
INSTALL | +3 | -3 |
src/anopa/aa-enable.c | +28 | -28 |
src/anopa/aa-reset.c | +7 | -6 |
src/anopa/aa-start.c | +12 | -16 |
src/anopa/aa-status.c | +26 | -27 |
src/anopa/aa-stop.c | +13 | -11 |
src/anopa/start-stop.c | +41 | -36 |
src/anopa/start-stop.h | +3 | -2 |
src/anopa/util.c | +8 | -6 |
src/include/anopa/ga_int_list.h | +6 | -15 |
src/include/anopa/ga_list.h | +36 | -0 |
src/include/anopa/output.h | +19 | -19 |
src/include/anopa/service.h | +20 | -20 |
src/libanopa/deps-lib/anopa | +1 | -1 |
src/libanopa/enable_service.c | +18 | -18 |
src/libanopa/exec_longrun.c | +13 | -13 |
src/libanopa/exec_oneshot.c | +22 | -22 |
src/libanopa/ga_int_list.c | +0 | -68 |
src/libanopa/ga_list.c | +77 | -0 |
src/libanopa/output.c | +5 | -5 |
src/libanopa/progress.c | +10 | -10 |
src/libanopa/scan_dir.c | +4 | -3 |
src/libanopa/service.c | +27 | -20 |
src/libanopa/service_internal.h | +3 | -2 |
src/libanopa/service_name.c | +5 | -4 |
src/libanopa/service_start.c | +7 | -6 |
src/libanopa/service_status.c | +8 | -8 |
src/libanopa/services.c | +2 | -2 |
src/libanopa/stats.c | +7 | -7 |
src/utils/aa-ctty.c | +3 | -3 |
src/utils/aa-incmdline.c | +5 | -5 |
src/utils/aa-kill.c | +5 | -6 |
src/utils/aa-mount.c | +6 | -5 |
src/utils/aa-mvlog.c | +2 | -2 |
src/utils/aa-service.c | +5 | -5 |
src/utils/aa-setready.c | +3 | -2 |
src/utils/aa-terminate.c | +13 | -10 |
src/utils/aa-test.c | +10 | -11 |
src/utils/aa-tty.c | +6 | -6 |
diff --git a/INSTALL b/INSTALL index 26944af..9b32518 100644 --- a/INSTALL +++ b/INSTALL @@ -6,9 +6,9 @@ Build Instructions - A POSIX-compliant C development environment - GNU make version 4.0 or later - - skalibs version 2.3.8.0 or later: http://skarnet.org/software/skalibs/ - - execline version 2.1.3.0 or later: http://skarnet.org/software/execline/ - - s6 version 2.2.4.3 or later: http://skarnet.org/software/s6/ + - skalibs version 2.5.0.0 or later: http://skarnet.org/software/skalibs/ + - execline version 2.3.0.1 or later: http://skarnet.org/software/execline/ + - s6 version 2.5.0.0 or later: http://skarnet.org/software/s6/ Noting that both execline and s6 are also runtime dependencies, the former only if using the aa-stage{0..4} scripts. diff --git a/src/anopa/aa-enable.c b/src/anopa/aa-enable.c index 2d3cbc6..d0dd70f 100644 --- a/src/anopa/aa-enable.c +++ b/src/anopa/aa-enable.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-enable.c - * Copyright (C) 2015-2016 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -27,6 +27,7 @@ #include <errno.h> #include <string.h> +#include <strings.h> #include <unistd.h> #include <getopt.h> #include <sys/stat.h> @@ -35,8 +36,7 @@ #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/direntry.h> -#include <skalibs/error.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/skamisc.h> #include <s6/s6-supervise.h> #include <anopa/common.h> @@ -44,7 +44,7 @@ #include <anopa/init_repo.h> #include <anopa/scan_dir.h> #include <anopa/enable_service.h> -#include <anopa/ga_int_list.h> +#include <anopa/ga_list.h> #include <anopa/stats.h> #include <anopa/err.h> #include "util.h" @@ -74,29 +74,29 @@ warn_cb (const char *name, int err) { aa_put_warn (cur_name, name, 0); aa_bs_noflush (AA_ERR, ": "); - aa_bs_noflush (AA_ERR, error_str (err)); + aa_bs_noflush (AA_ERR, strerror (err)); aa_end_warn (); } static void ae_cb (const char *name, aa_enable_flags type) { - int i; + size_t i; for (i = 0; i < names.len; i += strlen (names.s + i) + 1) if (str_equal (name, names.s + i)) return; - genalloc_append (int, &ga_next, &names.len); + genalloc_append (size_t, &ga_next, &names.len); stralloc_catb (&names, name, strlen (name) + 1); } static int enable_service (const char *name, intptr_t from_next) { - int offset; + size_t offset; + size_t i; int r; - int i; if (*name == '/') cur_name = name + byte_rchr (name, strlen (name), '/') + 1; @@ -113,11 +113,11 @@ enable_service (const char *name, intptr_t from_next) * - in upgrade mode, the auto-added are treated differently, so * anything specified needs to be treated now (even w/out folder) */ - for (i = 0; i < genalloc_len (int, &ga_next); ++i) - if (str_equal (cur_name, names.s + list_get (&ga_next, i))) + for (i = 0; i < genalloc_len (size_t, &ga_next); ++i) + if (str_equal (cur_name, names.s + ga_get (size_t, &ga_next, i))) { - offset = list_get (&ga_next, i); - ga_remove (int, &ga_next, i); + offset = ga_get (size_t, &ga_next, i); + ga_remove (&ga_next, sizeof (size_t), i); goto process; } @@ -140,11 +140,11 @@ process: if (r == -ERR_IO) { aa_bs_noflush (AA_ERR, ": "); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); } - genalloc_append (int, &ga_failed, &offset); + genalloc_append (size_t, &ga_failed, &offset); cur_name = NULL; return -1; } @@ -181,11 +181,11 @@ it_list (direntry *d, void *data) enable_service (d->d_name, 0); else { - int l; + size_t l; l = sa_pl.len; sa_pl.s[l - 1] = '/'; - stralloc_catb (&sa_pl, d->d_name, str_len (d->d_name) + 1); + stralloc_catb (&sa_pl, d->d_name, strlen (d->d_name) + 1); enable_service (sa_pl.s, 0); sa_pl.len = l; sa_pl.s[l - 1] = '\0'; @@ -377,13 +377,13 @@ main (int argc, char * const argv[]) else enable_service (argv[i], 0); - while (genalloc_len (int, &ga_next) > 0) + while (genalloc_len (size_t, &ga_next) > 0) { - int offset; + size_t offset; - i = genalloc_len (int, &ga_next) - 1; - offset = list_get (&ga_next, i); - genalloc_setlen (int, &ga_next, i); + i = genalloc_len (size_t, &ga_next) - 1; + offset = ga_get (size_t, &ga_next, i); + genalloc_setlen (size_t, &ga_next, i); if (!(flags & AA_FLAG_UPGRADE_SERVICEDIR)) enable_service (names.s + offset, 1 + offset); else @@ -399,7 +399,7 @@ main (int argc, char * const argv[]) aa_put_err (names.s + offset, errmsg[ERR_IO], 1); aa_bs_noflush (AA_ERR, ": " "unable to check for existing servicedir" ": "); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); } else @@ -420,11 +420,11 @@ main (int argc, char * const argv[]) if (!(flags & AA_FLAG_UPGRADE_SERVICEDIR)) { if ((set_crash || set_finish) && mkdir (SVSCANDIR, S_IRWXU) < 0) - aa_put_err ("Failed to create " SVSCANDIR, error_str (errno), 1); + aa_put_err ("Failed to create " SVSCANDIR, strerror (errno), 1); if (set_crash && symlink (set_crash, SCANDIR_CRASH) < 0) - aa_put_err ("Failed to create symlink " SCANDIR_CRASH, error_str (errno), 1); + aa_put_err ("Failed to create symlink " SCANDIR_CRASH, strerror (errno), 1); if (set_finish && symlink (set_finish, SCANDIR_FINISH) < 0) - aa_put_err ("Failed to create symlink " SCANDIR_FINISH, error_str (errno), 1); + aa_put_err ("Failed to create symlink " SCANDIR_FINISH, strerror (errno), 1); } if (alarm_s6) @@ -436,8 +436,8 @@ main (int argc, char * const argv[]) aa_strerr_diefu1x (2, "alarm s6-svscan: supervisor not listening"); } - genalloc_free (int, &ga_failed); - genalloc_free (int, &ga_next); + genalloc_free (size_t, &ga_failed); + genalloc_free (size_t, &ga_next); stralloc_free (&sa_pl); stralloc_free (&names); return 0; diff --git a/src/anopa/aa-reset.c b/src/anopa/aa-reset.c index 28f59bd..8f31940 100644 --- a/src/anopa/aa-reset.c +++ b/src/anopa/aa-reset.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-reset.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -25,9 +25,10 @@ #include "anopa/config.h" #include <errno.h> +#include <strings.h> #include <getopt.h> #include <skalibs/tai.h> -#include <skalibs/error.h> +#include <skalibs/bytestr.h> #include <anopa/common.h> #include <anopa/output.h> #include <anopa/init_repo.h> @@ -50,8 +51,8 @@ reset_service (const char *name, intptr_t mode) aa_service *s; int si; int r; - int old_event; - int event; + aa_evt old_event; + aa_evt event; r = aa_get_service (name, &si, 1); if (r < 0) @@ -73,7 +74,7 @@ reset_service (const char *name, intptr_t mode) int e = errno; aa_put_err (name, "Failed to read service status file: ", 0); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); return; } @@ -113,7 +114,7 @@ reset_service (const char *name, intptr_t mode) int e = errno; aa_put_err (name, "Failed to write service status file: ", 0); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); } else diff --git a/src/anopa/aa-start.c b/src/anopa/aa-start.c index e876295..d734be5 100644 --- a/src/anopa/aa-start.c +++ b/src/anopa/aa-start.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-start.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -26,6 +26,7 @@ #include <termios.h> #include <sys/ioctl.h> #include <langinfo.h> +#include <strings.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> @@ -37,12 +38,10 @@ #include <skalibs/bytestr.h> #include <skalibs/direntry.h> #include <skalibs/genalloc.h> -#include <skalibs/error.h> #include <skalibs/tai.h> #include <skalibs/iopause.h> #include <skalibs/djbunix.h> -#include <skalibs/uint16.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <anopa/common.h> #include <anopa/err.h> #include <anopa/init_repo.h> @@ -76,7 +75,7 @@ check_essential (int si) { struct stat st; const char *name = aa_service_name (aa_service (si)); - int l_name = strlen (name); + size_t l_name = strlen (name); char buf[l_name + 1 + sizeof (ESSENTIAL_FILENAME)]; byte_copy (buf, l_name, name); @@ -88,7 +87,7 @@ check_essential (int si) { int e = errno; put_warn (name, "Failed to stat " ESSENTIAL_FILENAME ": ", 0); - add_warn (error_str (e)); + add_warn (strerror (e)); end_warn (); } } @@ -157,10 +156,10 @@ add_service (const char *name, void *data) put_err_service (name, ERR_IO, 0); add_err (": "); - add_err (error_str (e)); + add_err (strerror (e)); end_err (); - genalloc_append (int, &ga_failed, &si); + add_to_list (&ga_failed, si, 0); check_essential (si); } } @@ -186,10 +185,7 @@ add_service (const char *name, void *data) end_err (); } - if (r == -ERR_DEPEND) - genalloc_append (int, &ga_depend, &si); - else - genalloc_append (int, &ga_failed, &si); + add_to_list ((r == -ERR_DEPEND) ? &ga_depend : &ga_failed, si, 0); check_essential (si); } } @@ -216,7 +212,7 @@ scan_cb (int si, int sni) add_err (": "); add_err (aa_service_name (aa_service (sni))); end_err (); - genalloc_append (int, &ga_depend, &si); + add_to_list (&ga_depend, si, 0); check_essential (si); } @@ -374,9 +370,9 @@ main (int argc, char * const argv[]) genalloc_free (int, &ga_timedout); genalloc_free (int, &ga_failed); genalloc_free (int, &ga_depend); - genalloc_free (int, &ga_unknown); - genalloc_free (int, &ga_io); - genalloc_free (int, &ga_skipped); + genalloc_free (size_t, &ga_io); + genalloc_free (size_t, &ga_unknown); + genalloc_free (size_t, &ga_skipped); genalloc_free (pid_t, &ga_pid); genalloc_free (int, &aa_tmp_list); genalloc_free (int, &aa_main_list); diff --git a/src/anopa/aa-status.c b/src/anopa/aa-status.c index faa8c26..f116fd5 100644 --- a/src/anopa/aa-status.c +++ b/src/anopa/aa-status.c @@ -26,6 +26,7 @@ #include <sys/ioctl.h> #include <termios.h> +#include <strings.h> #include <errno.h> #include <getopt.h> #include <unistd.h> @@ -37,11 +38,10 @@ #include <skalibs/genalloc.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/djbtime.h> #include <skalibs/tai.h> #include <skalibs/sig.h> -#include <skalibs/error.h> #include <s6/s6-supervise.h> #include <anopa/common.h> #include <anopa/output.h> @@ -63,8 +63,8 @@ enum struct config { int mode; - int cols; - int max_name; + size_t cols; + size_t max_name; }; struct serv @@ -102,10 +102,10 @@ static unsigned int filter_type = FILTER_NONE; static unsigned int filter_status = FILTER_NONE; static unsigned int sort_order = SORT_ASC; -static int put_s_max (const char *s, int max, int pad); +static size_t put_s_max (const char *s, size_t max, int pad); static void -put_wstat (int wstat, int max, int pad) +put_wstat (int wstat, size_t max, int pad) { char buf[20]; @@ -182,7 +182,7 @@ put_time (tain_t *st_stamp, int strict) static struct col { const char *title; - int len; + size_t len; } cols[4] = { { .title = "Service", .len = 8 }, { .title = "Type", .len = 8 }, @@ -191,14 +191,14 @@ static struct col }; static inline void -pad_with (int left) +pad_with (ssize_t left) { for ( ; left > 0; left -= 10) aa_bb_noflush (AA_OUT, " ", (left >= 10) ? 10 : left); } static inline void -pad_col (int i, int done) +pad_col (int i, size_t done) { if (cols[i].len && cols[i].len > done) pad_with (cols[i].len - done); @@ -207,7 +207,7 @@ pad_col (int i, int done) static int put_list_header (struct config *cfg) { - int best; + size_t best; int i; if (cfg->max_name + 1 > cols[0].len) @@ -215,14 +215,14 @@ put_list_header (struct config *cfg) else best = cols[0].len; - if (cfg->cols < 0) + if (cfg->cols == 0) { cols[0].len = best; cols[3].len = 0; } else { - int len; + size_t len; /* try with the best width */ len = best + cols[1].len + cols[2].len + cols[3].len; @@ -230,8 +230,8 @@ put_list_header (struct config *cfg) cols[0].len = best; else { - int added; - int n; + size_t added; + size_t n; added = best - cols[0].len; n = len - cfg->cols; @@ -279,10 +279,10 @@ put_list_header (struct config *cfg) return 1; } -static int -put_s_max (const char *s, int max, int pad) +static size_t +put_s_max (const char *s, size_t max, int pad) { - int l = strlen (s); + size_t l = strlen (s); if (max <= 4) return 0; @@ -378,7 +378,7 @@ status_service (struct serv *serv, struct config *cfg) if (serv->is_s6) { - int max = cols[3].len; + size_t max = cols[3].len; if (serv->st6.pid && !serv->st6.flagfinishing) { @@ -452,7 +452,7 @@ status_service (struct serv *serv, struct config *cfg) } else { - int max = cols[3].len; + size_t max = cols[3].len; switch (s->st.event) { @@ -628,7 +628,7 @@ load_service (const char *name, struct config *cfg) int e = errno; aa_put_err (name, "Failed to read service status file: ", 0); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); return -1; } @@ -648,7 +648,7 @@ load_service (const char *name, struct config *cfg) int e = errno; aa_put_err (name, "Unable to read s6 status: ", 0); - aa_bs_noflush (AA_ERR, error_str (e)); + aa_bs_noflush (AA_ERR, strerror (e)); aa_end_err (); return -1; } @@ -670,7 +670,7 @@ load_service (const char *name, struct config *cfg) if (cfg->mode == MODE_LIST) { - int l = strlen (name); + size_t l = strlen (name); if (l > cfg->max_name) cfg->max_name = l; @@ -694,8 +694,8 @@ it_all (direntry *d, void *data) /* si < 0 could be a error, or just that it was filtered out */ && (si < 0 || aa_service (si)->st.type == AA_TYPE_LONGRUN)) { - int l = satmp.len; - int ln = strlen (d->d_name); + size_t l = satmp.len; + size_t ln = strlen (d->d_name); int r; /* is this not a logger already? */ @@ -818,7 +818,6 @@ main (int argc, char * const argv[]) struct config cfg = { 0, }; int (*sort_fn) (const void *, const void *) = cmp_serv_stamp; int all = 0; - int i; int r; for (;;) @@ -958,7 +957,7 @@ main (int argc, char * const argv[]) (*path_list != '/' && *path_list != '.') ? path_list : ""); } else - for (i = 0; i < argc; ++i) + for (int i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) load_service, &cfg) < 0) @@ -971,7 +970,7 @@ main (int argc, char * const argv[]) qsort (genalloc_s(struct serv, &ga_serv), genalloc_len (struct serv, &ga_serv), sizeof (struct serv), sort_fn); - for (i = 0; i < genalloc_len (struct serv, &ga_serv); ++i) + for (size_t i = 0; i < genalloc_len (struct serv, &ga_serv); ++i) status_service (&genalloc_s (struct serv, &ga_serv)[i], &cfg); return 0; diff --git a/src/anopa/aa-stop.c b/src/anopa/aa-stop.c index 2d89ddc..3864dac 100644 --- a/src/anopa/aa-stop.c +++ b/src/anopa/aa-stop.c @@ -22,6 +22,7 @@ #define _BSD_SOURCE +#include <strings.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> @@ -32,8 +33,7 @@ #include <skalibs/direntry.h> #include <skalibs/genalloc.h> #include <skalibs/skamisc.h> -#include <skalibs/error.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/tai.h> #include <skalibs/djbunix.h> #include <s6/s6-supervise.h> @@ -108,7 +108,7 @@ preload_service (const char *name) put_err_service (name, ERR_IO, 0); add_err (": "); - add_err (error_str (e)); + add_err (strerror (e)); end_err (); } } @@ -119,7 +119,7 @@ preload_service (const char *name) * need to always check for a logger */ if (r < 0 || aa_service (si)->st.type == AA_TYPE_LONGRUN) { - int l = satmp.len; + size_t l = satmp.len; /* for longruns, even though the dependency of the logger is auto-added, * we still need to ensure the service is loaded */ @@ -194,10 +194,10 @@ add_service (const char *name, void *data) put_err_service (name, ERR_IO, 0); add_err (": "); - add_err (error_str (e)); + add_err (strerror (e)); end_err (); - genalloc_append (int, &ga_failed, &si); + add_to_list (&ga_failed, si, 0); } } } @@ -220,7 +220,7 @@ add_service (const char *name, void *data) } else { - int i; + size_t i; add_to_list (&aa_main_list, si, 0); remove_from_list (&aa_tmp_list, si); @@ -255,7 +255,7 @@ scan_cb (int si, int sni) add_err (": "); add_err (aa_service_name (aa_service (sni))); end_err (); - genalloc_append (int, &ga_depend, &si); + add_to_list (&ga_depend, si, 0); } static void @@ -285,7 +285,7 @@ static void stop_supervise_for (int si) { aa_service *s = aa_service (si); - int l_sn = strlen (aa_service_name (s)); + size_t l_sn = strlen (aa_service_name (s)); char dir[l_sn + 1 + sizeof (S6_SUPERVISE_CTLDIR) + 8]; int r; @@ -422,6 +422,8 @@ main (int argc, char * const argv[]) if (all) { + size_t i; + /* to stop all (up) services, since we've preloaded everything, simply * means moving all services from tmp to main list. We just need to make * sure to process "valid" services, since there could be LOAD_FAIL ones @@ -501,9 +503,9 @@ main (int argc, char * const argv[]) genalloc_free (int, &ga_timedout); genalloc_free (int, &ga_failed); - genalloc_free (int, &ga_unknown); genalloc_free (int, &ga_depend); - genalloc_free (int, &ga_io); + genalloc_free (size_t, &ga_io); + genalloc_free (size_t, &ga_unknown); genalloc_free (pid_t, &ga_pid); genalloc_free (int, &aa_tmp_list); genalloc_free (int, &aa_main_list); diff --git a/src/anopa/start-stop.c b/src/anopa/start-stop.c index 62b1ac7..4fbd2c3 100644 --- a/src/anopa/start-stop.c +++ b/src/anopa/start-stop.c @@ -25,6 +25,7 @@ #include <sys/ioctl.h> #include <langinfo.h> #include <errno.h> +#include <unistd.h> #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> #include <skalibs/bytestr.h> @@ -34,8 +35,7 @@ #include <skalibs/iopause.h> #include <skalibs/selfpipe.h> #include <skalibs/sig.h> -#include <skalibs/uint.h> -#include <skalibs/uint16.h> +#include <skalibs/types.h> #include <anopa/service.h> #include <anopa/ga_int_list.h> #include <anopa/output.h> @@ -82,7 +82,7 @@ clear_draw () if (draw & DRAW_CUR_PROGRESS) { - int i; + size_t i; for (i = 0; i < genalloc_len (struct progress, &ga_progress); ++i) { @@ -181,7 +181,7 @@ draw_waiting (int already_drawn) else ++tick; - if (n <= genalloc_len (pid_t, &ga_pid)) + if ((size_t) n <= genalloc_len (pid_t, &ga_pid)) si = list_get (&aa_tmp_list, n - 1); else { @@ -286,7 +286,7 @@ refresh_draw () if ((draw & DRAW_NEED_PASSWORD) && si_password < 0) { - int i; + size_t i; for (i = 0; i < genalloc_len (struct progress, &ga_progress); ++i) { @@ -321,7 +321,7 @@ refresh_draw () if (draw & DRAW_NEED_PROGRESS) { - int i; + size_t i; for (i = 0; i < genalloc_len (struct progress, &ga_progress); ++i) { @@ -350,19 +350,24 @@ refresh_draw () void add_name_to_ga (const char *name, genalloc *ga) { - int offset = aa_add_name (name); - genalloc_append (int, ga, &offset); + size_t offset = aa_add_name (name); + if (offset == (size_t) -1) + { + aa_strerr_warnu3sys ("add '", name, "' to list"); + return; + } + genalloc_append (size_t, ga, &offset); } void remove_fd_from_iop (int fd) { - int i; + size_t i; for (i = 0; i < genalloc_len (iopause_fd, &ga_iop); ++i) if (genalloc_s (iopause_fd, &ga_iop)[i].fd == fd) { - ga_remove (iopause_fd, &ga_iop, i); + ga_remove (&ga_iop, sizeof (iopause_fd), i); break; } } @@ -372,7 +377,7 @@ close_fd_for (int fd, int si) { if (si < 0) { - int i; + size_t i; for (i = 0; i < genalloc_len (int, &aa_tmp_list); ++i) if (aa_service (list_get (&aa_tmp_list, i))->fd_in == fd @@ -417,7 +422,7 @@ handle_fd_out (int si) for (;;) { char buf[256]; - int r; + ssize_t r; r = fd_read (s->fd_out, buf, 256); if (r < 0) @@ -433,7 +438,7 @@ handle_fd_out (int si) for (;;) { - int len; + size_t len; len = byte_chr (s->sa_out.s, s->sa_out.len, '\n'); if (len >= s->sa_out.len) @@ -460,8 +465,8 @@ handle_fd_progress (int si) aa_service *s = aa_service (si); struct progress *pg; char buf[256]; - int i; - int r; + size_t i; + ssize_t r; if (s->pi < 0) { @@ -501,7 +506,7 @@ handle_fd_progress (int si) /* PASSWORD */ if ((r > 3 && buf[1] == '<' && buf[2] == ' ') || pg->is_drawn == DRAWN_PASSWORD_WAITMSG) { - int rr; + size_t rr; if (pg->is_drawn != DRAWN_PASSWORD_WAITMSG) { @@ -512,7 +517,7 @@ handle_fd_progress (int si) i = 1; rr = byte_rchr (buf + i, r, '\n'); - if (rr == r) + if (rr == (size_t) r) { if (!stralloc_catb (&pg->aa_pg.sa, buf + i, rr)) return -1; @@ -570,7 +575,7 @@ handle_fd_in (void) struct progress *pg; char buf[256]; iopause_fd iop; - int r; + ssize_t r; r = fd_read (0, buf, 256); if (r < 0) @@ -604,7 +609,7 @@ int handle_fd (int fd) { int si; - int i; + size_t i; if (fd == 0 && si_password >= 0) return handle_fd_in (); @@ -661,9 +666,9 @@ handle_fdw (int fd) { aa_service *s; struct progress *pg; - int offset; - int len; - int r; + size_t offset; + size_t len; + ssize_t r; if (si_password < 0 || aa_service (si_password)->fd_in != fd) return (errno = ENOENT, -1); @@ -680,7 +685,7 @@ handle_fdw (int fd) aa_strerr_warnu2sys ("write to fd_in of service ", aa_service_name (s)); return r; } - else if (r < len) + else if ((size_t) r < len) { memmove (pg->aa_pg.sa.s + offset, pg->aa_pg.sa.s + offset + r, len - r); pg->aa_pg.sa.len -= r; @@ -712,7 +717,7 @@ handle_oneshot (int is_start) si = list_get (&aa_tmp_list, r - 1); remove_from_list (&aa_tmp_list, si); - ga_remove (pid_t, &ga_pid, r - 1); + ga_remove (&ga_pid, sizeof (pid_t), r - 1); if (si == si_password) end_si_password (); if (aa_service (si)->fd_in > 0) @@ -793,11 +798,11 @@ handle_oneshot (int is_start) } int -handle_longrun (aa_mode mode, uint16 id, char event) +handle_longrun (aa_mode mode, uint16_t id, char event) { int si; - int l = genalloc_len (int, &aa_main_list); - int i; + size_t l = genalloc_len (int, &aa_main_list); + size_t i; for (i = 0; i < l; ++i) if (aa_service (list_get (&aa_main_list, i))->ft_id == id) @@ -919,10 +924,10 @@ handle_signals (aa_mode mode) } void -prepare_cb (int cur, int next, int is_needs, int first) +prepare_cb (int cur, int next, int is_needs, size_t first) { - int l = genalloc_len (int, &aa_tmp_list); - int i; + size_t l = genalloc_len (int, &aa_tmp_list); + size_t i; if (is_needs) { @@ -1045,8 +1050,8 @@ int process_timeouts (aa_mode mode, aa_scan_cb scan_cb) { int si; - int l; - int i; + size_t l; + size_t i; tain_t ts_timeout; tain_t ts; tain_t tms; @@ -1081,7 +1086,7 @@ process_timeouts (aa_mode mode, aa_scan_cb scan_cb) kill (genalloc_s (pid_t, &ga_pid)[i], SIGKILL); remove_from_list (&aa_tmp_list, si); - ga_remove (pid_t, &ga_pid, i); + ga_remove (&ga_pid, sizeof (pid_t), i); if (si == si_password) end_si_password (); if (aa_service (si)->fd_in > 0) @@ -1188,7 +1193,7 @@ mainloop (aa_mode mode, aa_scan_cb scan_cb) { sigset_t set; iopause_fd iop; - int i; + size_t i; if (!genalloc_ready_tuned (iopause_fd, &ga_iop, 2, 0, 0, 1)) aa_strerr_diefu1sys (ERR_IO, "allocate iopause_fd"); @@ -1305,7 +1310,7 @@ mainloop (aa_mode mode, aa_scan_cb scan_cb) { for (;;) { - uint16 id; + uint16_t id; char event; r = aa_get_longrun_info (&id, &event); @@ -1340,7 +1345,7 @@ scan: void show_stat_service_names (genalloc *ga, const char *title, const char *ansi_color) { - int i; + size_t i; if (genalloc_len (int, ga) <= 0) return; diff --git a/src/anopa/start-stop.h b/src/anopa/start-stop.h index dbe538f..e364643 100644 --- a/src/anopa/start-stop.h +++ b/src/anopa/start-stop.h @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * start-stop.h - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -24,6 +24,7 @@ #define AA_START_STOP_H #include <signal.h> +#include <sys/types.h> #include <skalibs/genalloc.h> #include <skalibs/tai.h> #include <anopa/service.h> @@ -102,7 +103,7 @@ int handle_longrun (aa_mode mode, uint16 id, char event); int is_locale_utf8 (void); int get_cols (int fd); int handle_signals (aa_mode mode); -void prepare_cb (int cur, int next, int is_needs, int first); +void prepare_cb (int cur, int next, int is_needs, size_t first); void exec_cb (int si, aa_evt evt, pid_t pid); void mainloop (aa_mode mode, aa_scan_cb scan_cb); void show_stat_service_names (genalloc *ga, const char *title, const char *ansi_color); diff --git a/src/anopa/util.c b/src/anopa/util.c index 34994ca..8e2d738 100644 --- a/src/anopa/util.c +++ b/src/anopa/util.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * util.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -20,17 +20,17 @@ * anopa. If not, see http://www.gnu.org/licenses/ */ +#include <string.h> +#include <errno.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> #include <skalibs/skamisc.h> -#include <string.h> -#include <errno.h> #include "util.h" int process_names_from_stdin (names_cb process_name, void *data) { - int salen = satmp.len; + size_t salen = satmp.len; int r; for (;;) @@ -62,9 +62,11 @@ process_names_from_stdin (names_cb process_name, void *data) void unslash (char *s) { - int l = strlen (s) - 1; - if (l <= 0) + size_t l = strlen (s); + + if (l <= 1) return; + --l; if (s[l] == '/') s[l] = '\0'; } diff --git a/src/include/anopa/ga_int_list.h b/src/include/anopa/ga_int_list.h index 2e8befb..4459908 100644 --- a/src/include/anopa/ga_int_list.h +++ b/src/include/anopa/ga_int_list.h @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * ga_int_list.h - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -23,20 +23,11 @@ #ifndef AA_GA_INT_LIST_H #define AA_GA_INT_LIST_H -#include <skalibs/genalloc.h> +#include <anopa/ga_list.h> -#define ga_remove(type, ga, i) do { \ - int len = (ga)->len / sizeof (type); \ - int 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) - -#define list_get(ga, i) (genalloc_s (int, ga)[i]) - -extern int add_to_list (genalloc *list, int si, int check_for_dupes); -extern int remove_from_list (genalloc *list, int si); -extern int is_in_list (genalloc *list, int si); +#define list_get(ga, i) ga_get (int, ga, i) +#define add_to_list(ga, si, chk_dupes) ga_add_val (ga, sizeof (int), (char const *) &si, chk_dupes) +#define remove_from_list(ga, si) ga_remove_val (ga, sizeof (int), (char const *) &si) +#define is_in_list(ga, si) (ga_find (ga, sizeof (int), (char const *) &si) >= 0) #endif /* AA_GA_INT_LIST_H */ diff --git a/src/include/anopa/ga_list.h b/src/include/anopa/ga_list.h new file mode 100644 index 0000000..a27e993 --- /dev/null +++ b/src/include/anopa/ga_list.h @@ -0,0 +1,36 @@ +/* + * anopa - Copyright (C) 2015-2016 Olivier Brunel + * + * ga_list.h + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> + * + * This file is part of anopa. + * + * anopa is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * anopa is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * anopa. If not, see http://www.gnu.org/licenses/ + */ + +#ifndef AA_GA_LIST_H +#define AA_GA_LIST_H + +#include <sys/types.h> +#include <skalibs/genalloc.h> + +#define ga_get(type, ga, i) (genalloc_s (type, ga)[i]) + +void ga_remove (genalloc *ga, size_t size, int i); +int ga_find (genalloc *ga, size_t size, void const *val); +int ga_add_val (genalloc *ga, size_t size, void const *val, int check_for_dupes); +int ga_remove_val (genalloc *ga, size_t size, void const *val); + +#endif /* AA_GA_LIST_H */ diff --git a/src/include/anopa/output.h b/src/include/anopa/output.h index 570186d..c07a24b 100644 --- a/src/include/anopa/output.h +++ b/src/include/anopa/output.h @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * output.h - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -23,8 +23,8 @@ #ifndef AA_OUTPUT_H #define AA_OUTPUT_H -#include <string.h> /* strlen() */ -#include <skalibs/error.h> +#include <string.h> +#include <errno.h> extern const char *PROG; @@ -39,12 +39,12 @@ extern const char *PROG; #define AA_ERR 1 extern void aa_set_double_output (int enabled); -extern void aa_bb_noflush (int where, const char *s, int len); -extern void aa_bb_flush (int where, const char *s, int len); +extern void aa_bb_noflush (int where, const char *s, size_t len); +extern void aa_bb_flush (int where, const char *s, size_t len); #define aa_bs_noflush(w,s) aa_bb_noflush ((w), (s), strlen (s)) #define aa_bs_flush(w,s) aa_bb_flush ((w), (s), strlen (s)) -extern void aa_ib_noflush (int where, const char *s, int len); -extern void aa_ib_flush (int where, const char *s, int len); +extern void aa_ib_noflush (int where, const char *s, size_t len); +extern void aa_ib_flush (int where, const char *s, size_t len); #define aa_is_noflush(w,s) aa_ib_noflush ((w), (s), strlen (s)) #define aa_is_flush(w,s) aa_ib_flush ((w), (s), strlen (s)) extern void aa_bs_end (int where); @@ -93,17 +93,17 @@ extern void aa_strerr_warn (const char *s1, aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, s5, s6, 0, 0) #define aa_strerr_warnu1sys(s1) \ - aa_strerr_warn ("warning: ", "unable to ", s1, ": ", error_str (errno), 0, 0, 0, 0, 0) + aa_strerr_warn ("warning: ", "unable to ", s1, ": ", strerror (errno), 0, 0, 0, 0, 0) #define aa_strerr_warnu2sys(s1,s2) \ - aa_strerr_warn ("warning: ", "unable to ", s1, s2, ": ", error_str (errno), 0, 0, 0, 0) + aa_strerr_warn ("warning: ", "unable to ", s1, s2, ": ", strerror (errno), 0, 0, 0, 0) #define aa_strerr_warnu3sys(s1,s2,s3) \ - aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, ": ", error_str (errno), 0, 0, 0) + aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, ": ", strerror (errno), 0, 0, 0) #define aa_strerr_warnu4sys(s1,s2,s3,s4) \ - aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, ": ", error_str (errno), 0, 0) + aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, ": ", strerror (errno), 0, 0) #define aa_strerr_warnu5sys(s1,s2,s3,s4,s5) \ - aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, s5, ": ", error_str (errno), 0) + aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, s5, ": ", strerror (errno), 0) #define aa_strerr_warnu6sys(s1,s2,s3,s4,s5,s6) \ - aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, s5, s6, ": ", error_str (errno)) + aa_strerr_warn ("warning: ", "unable to ", s1, s2, s3, s4, s5, s6, ": ", strerror (errno)) extern void aa_strerr_die (int rc, const char *s1, @@ -117,17 +117,17 @@ extern void aa_strerr_die (int rc, const char *s9); #define aa_strerr_diefu1sys(rc,s1) \ - aa_strerr_die (rc, "unable to ", s1, ": ", error_str (errno), 0, 0, 0, 0, 0) + aa_strerr_die (rc, "unable to ", s1, ": ", strerror (errno), 0, 0, 0, 0, 0) #define aa_strerr_diefu2sys(rc,s1,s2) \ - aa_strerr_die (rc, "unable to ", s1, s2, ": ", error_str (errno), 0, 0, 0, 0) + aa_strerr_die (rc, "unable to ", s1, s2, ": ", strerror (errno), 0, 0, 0, 0) #define aa_strerr_diefu3sys(rc,s1,s2,s3) \ - aa_strerr_die (rc, "unable to ", s1, s2, s3, ": ", error_str (errno), 0, 0, 0) + aa_strerr_die (rc, "unable to ", s1, s2, s3, ": ", strerror (errno), 0, 0, 0) #define aa_strerr_diefu4sys(rc,s1,s2,s3,s4) \ - aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, ": ", error_str (errno), 0, 0) + aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, ": ", strerror (errno), 0, 0) #define aa_strerr_diefu5sys(rc,s1,s2,s3,s4,s5) \ - aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, s5, ": ", error_str (errno), 0) + aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, s5, ": ", strerror (errno), 0) #define aa_strerr_diefu6sys(rc,s1,s2,s3,s4,s5,s6) \ - aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, s5, s6, ": ", error_str (errno)) + aa_strerr_die (rc, "unable to ", s1, s2, s3, s4, s5, s6, ": ", strerror (errno)) #define aa_strerr_dief1x(rc,s1) \ aa_strerr_die (rc, s1, 0, 0, 0, 0, 0, 0, 0, 0) diff --git a/src/include/anopa/service.h b/src/include/anopa/service.h index 99563e3..f24679e 100644 --- a/src/include/anopa/service.h +++ b/src/include/anopa/service.h @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * service.h - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -23,12 +23,12 @@ #ifndef AA_SERVICE_H #define AA_SERVICE_H +#include <stdint.h> +#include <sys/types.h> #include <signal.h> /* pid_t */ #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> -#include <skalibs/uint16.h> #include <skalibs/tai.h> -#include <s6/ftrigr.h> #include <anopa/service_status.h> #define AA_START_FILENAME "start" @@ -40,7 +40,7 @@ extern stralloc aa_names; extern genalloc aa_main_list; extern genalloc aa_tmp_list; extern genalloc aa_pid_list; -extern int aa_secs_timeout; +extern unsigned int aa_secs_timeout; #define aa_service(i) (&((aa_service *) aa_services.s)[i]) #define aa_service_name(service) (aa_names.s + (service)->offset_name) @@ -77,17 +77,17 @@ typedef enum typedef struct { - int offset_name; + size_t offset_name; int nb_mark; genalloc needs; genalloc wants; genalloc after; - int secs_timeout; + unsigned int secs_timeout; aa_ls ls; aa_service_status st; tain_t ts_exec; /* longrun */ - uint16 ft_id; + uint16_t ft_id; int gets_ready; /* oneshot */ int fd_in; @@ -100,21 +100,21 @@ typedef struct typedef void (*aa_close_fd_fn) (int fd); typedef void (*aa_autoload_cb) (int si, aa_al al, const char *name, int err); -typedef void (*aa_prepare_cb) (int si, int si_next, int is_needs, int first); +typedef void (*aa_prepare_cb) (int si, int si_next, int is_needs, size_t first); typedef void (*aa_scan_cb) (int si, int sni); typedef void (*aa_exec_cb) (int si, aa_evt evt, pid_t pid); -extern void aa_free_services (aa_close_fd_fn close_fd_fn); -extern int aa_add_name (const char *name); -extern int aa_get_service (const char *name, int *si, int new_in_main); -extern void aa_unmark_service (int si); -extern int aa_mark_service (aa_mode mode, int si, int in_main, int no_wants, aa_autoload_cb al_cb); -extern int aa_preload_service (int si); -extern int aa_ensure_service_loaded (int si, aa_mode mode, int no_wants, aa_autoload_cb al_cb); -extern int aa_prepare_mainlist (aa_prepare_cb prepare_cb, aa_exec_cb exec_cb); -extern void aa_scan_mainlist (aa_scan_cb scan_cb, aa_mode mode); -extern int aa_exec_service (int si, aa_mode mode); -extern int aa_get_longrun_info (uint16 *id, char *event); -extern int aa_unsubscribe_for (uint16 id); +extern void aa_free_services (aa_close_fd_fn close_fd_fn); +extern size_t aa_add_name (const char *name); +extern int aa_get_service (const char *name, int *si, int new_in_main); +extern void aa_unmark_service (int si); +extern int aa_mark_service (aa_mode mode, int si, int in_main, int no_wants, aa_autoload_cb al_cb); +extern int aa_preload_service (int si); +extern int aa_ensure_service_loaded (int si, aa_mode mode, int no_wants, aa_autoload_cb al_cb); +extern int aa_prepare_mainlist (aa_prepare_cb prepare_cb, aa_exec_cb exec_cb); +extern void aa_scan_mainlist (aa_scan_cb scan_cb, aa_mode mode); +extern int aa_exec_service (int si, aa_mode mode); +extern int aa_get_longrun_info (uint16_t *id, char *event); +extern int aa_unsubscribe_for (uint16_t id); #endif /* AA_SERVICE_H */ diff --git a/src/libanopa/deps-lib/anopa b/src/libanopa/deps-lib/anopa index 95eb75b..37bf943 100644 --- a/src/libanopa/deps-lib/anopa +++ b/src/libanopa/deps-lib/anopa @@ -6,7 +6,7 @@ errmsg.o eventmsg.o exec_longrun.o exec_oneshot.o -ga_int_list.o +ga_list.o init_repo.o output.o progress.o diff --git a/src/libanopa/enable_service.c b/src/libanopa/enable_service.c index 67fb31c..2aa15ef 100644 --- a/src/libanopa/enable_service.c +++ b/src/libanopa/enable_service.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * enable_service.c - * Copyright (C) 2015-2016 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -42,7 +42,7 @@ static int copy_from_source (const char *name, - int len, + size_t len, aa_warn_fn warn_fn, aa_enable_flags flags, aa_auto_enable_cb ae_cb); @@ -112,7 +112,7 @@ static int clear_dir (const char *path, int excludes, aa_warn_fn warn_fn) { DIR *dir; - int salen = satmp.len; + size_t salen = satmp.len; dir = opendir (path); if (!dir) @@ -229,7 +229,7 @@ copy_dir (const char *src, for (;;) { direntry *d; - unsigned int len; + size_t len; d = readdir (dir); if (!d) @@ -310,10 +310,10 @@ copy_dir (const char *src, } { - unsigned int l_inst = (instance) ? strlen (instance) : 0; - unsigned int l_src = strlen (src); - unsigned int l_dst = strlen (dst); - unsigned int i = l_satmp; + size_t l_inst = (instance) ? strlen (instance) : 0; + size_t l_src = strlen (src); + size_t l_dst = strlen (dst); + size_t i = l_satmp; char buf_src[l_src + 1 + l_max + 1]; char buf_dst[l_dst + 1 + l_max + l_inst + 1]; @@ -324,7 +324,7 @@ copy_dir (const char *src, while (i < satmp.len) { - unsigned int len; + size_t len; int r; len = strlen (satmp.s + i); @@ -412,7 +412,7 @@ copy_dir (const char *src, r = mkfifo (buf_dst, st.st_mode); else if (S_ISLNK (st.st_mode)) { - unsigned int l_tmp = satmp.len; + size_t l_tmp = satmp.len; if ((sareadlink (&satmp, buf_src) < 0) || !stralloc_0 (&satmp)) r = -1; @@ -513,7 +513,7 @@ err: return -ERR_IO; else { - unsigned int l_dst = strlen (dst); + size_t l_dst = strlen (dst); char buf[1 + l_dst + 1]; *buf = '@'; @@ -531,12 +531,12 @@ err: static int copy_from_source (const char *name, - int len, + size_t len, aa_warn_fn warn_fn, aa_enable_flags flags, aa_auto_enable_cb ae_cb) { - int i; + size_t i; if (aa_sa_sources.len == 0) return -ERR_UNKNOWN; @@ -544,7 +544,7 @@ copy_from_source (const char *name, i = 0; for (;;) { - int l_sce = strlen (aa_sa_sources.s + i); + size_t l_sce = strlen (aa_sa_sources.s + i); char buf[l_sce + 1 + len + 1]; struct stat st; @@ -590,7 +590,7 @@ do_auto_needs_wants (const char *name, aa_enable_flags flags, aa_auto_enable_cb aa_auto_enable_cb cb; unsigned int flag; } data = { .cb = ae_cb }; - int l_name = strlen (name); + size_t l_name = strlen (name); int r = 0; if (!stralloc_catb (&sa, name, l_name)) @@ -645,8 +645,8 @@ aa_enable_service (const char *_name, const char *name = _name; const char *instance = NULL; mode_t _mode = 0; /* silence warning */ - int l_name = strlen (name); - int len; + size_t l_name = strlen (name); + size_t len; int has_log = 0; int r; @@ -703,7 +703,7 @@ aa_enable_service (const char *_name, if (has_log) { - int l = sizeof ("/log/run-args"); + size_t l = sizeof ("/log/run-args"); char buf[l_name + l]; struct stat st; diff --git a/src/libanopa/exec_longrun.c b/src/libanopa/exec_longrun.c index c620f2a..6e287d2 100644 --- a/src/libanopa/exec_longrun.c +++ b/src/libanopa/exec_longrun.c @@ -21,11 +21,11 @@ */ #include <unistd.h> +#include <strings.h> #include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/bytestr.h> #include <skalibs/tai.h> -#include <skalibs/error.h> #include <s6/s6-supervise.h> #include <s6/ftrigr.h> #include <anopa/service.h> @@ -38,7 +38,7 @@ _exec_longrun (int si, aa_mode mode) { aa_service *s = aa_service (si); s6_svstatus_t st6 = S6_SVSTATUS_ZERO; - int l_sn = strlen (aa_service_name (s)); + size_t l_sn = strlen (aa_service_name (s)); char fifodir[l_sn + 1 + sizeof (S6_SUPERVISE_EVENTDIR)]; tain_t deadline; int is_start = (mode & AA_MODE_START) ? 1 : 0; @@ -60,9 +60,9 @@ _exec_longrun (int si, aa_mode mode) * something failed during aa-enable for example */ const char *errmsg = "Failed to subscribe to eventdir: "; - int l_msg = strlen (errmsg); - const char *errstr = error_str (errno); - int l_err = strlen (errstr); + size_t l_msg = strlen (errmsg); + const char *errstr = strerror (errno); + size_t l_err = strlen (errstr); char msg[l_msg + l_err + 1]; byte_copy (msg, l_msg, errmsg); @@ -143,7 +143,7 @@ _exec_longrun (int si, aa_mode mode) { s->st.event = (is_start) ? AA_EVT_STARTING_FAILED : AA_EVT_STOPPING_FAILED; s->st.code = ERR_WRITE_STATUS; - aa_service_status_set_msg (&s->st, error_str (errno)); + aa_service_status_set_msg (&s->st, strerror (errno)); if (_exec_cb) _exec_cb (si, s->st.event, 0); @@ -215,14 +215,14 @@ _exec_longrun (int si, aa_mode mode) return 0; } -static int idx = -1; +static size_t idx = (size_t) -1; int -aa_get_longrun_info (uint16 *id, char *event) +aa_get_longrun_info (uint16_t *id, char *event) { int r; - if (idx == -1) + if (idx == (size_t) -1) { r = ftrigr_update (&_aa_ft); if (r < 0) @@ -232,21 +232,21 @@ aa_get_longrun_info (uint16 *id, char *event) idx = 0; } - for ( ; idx < genalloc_len (uint16, &_aa_ft.list); ) + for ( ; idx < genalloc_len (uint16_t, &_aa_ft.list); ) { - *id = genalloc_s (uint16, &_aa_ft.list)[idx]; + *id = genalloc_s (uint16_t, &_aa_ft.list)[idx]; r = ftrigr_check (&_aa_ft, *id, event); ++idx; if (r != 0) return (r < 0) ? -2 : r; } - idx = -1; + idx = (size_t) -1; return 0; } int -aa_unsubscribe_for (uint16 id) +aa_unsubscribe_for (uint16_t id) { tain_t deadline; diff --git a/src/libanopa/exec_oneshot.c b/src/libanopa/exec_oneshot.c index b700271..292f74e 100644 --- a/src/libanopa/exec_oneshot.c +++ b/src/libanopa/exec_oneshot.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * exec_oneshot.c - * Copyright (C) 2015-2016 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -23,6 +23,7 @@ #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> +#include <strings.h> #include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> @@ -30,8 +31,7 @@ #include <skalibs/selfpipe.h> #include <skalibs/bytestr.h> #include <skalibs/tai.h> -#include <skalibs/uint32.h> -#include <skalibs/error.h> +#include <skalibs/types.h> #include <anopa/service.h> #include <anopa/err.h> #include <anopa/output.h> @@ -43,12 +43,12 @@ _exec_oneshot (int si, aa_mode mode) aa_service *s = aa_service (si); int is_start = (mode & AA_MODE_START) ? 1 : 0; char * const filename = (is_start) ? AA_START_FILENAME : AA_STOP_FILENAME; - int l_fn = (is_start) ? sizeof(AA_START_FILENAME) : sizeof(AA_STOP_FILENAME); - int l_sn = strlen (aa_service_name (s)); + size_t l_fn = (is_start) ? sizeof(AA_START_FILENAME) : sizeof(AA_STOP_FILENAME); + size_t l_sn = strlen (aa_service_name (s)); char buf[l_sn + 1 +l_fn]; struct stat st; - const char *_err; - int _errno; + const char *_err = NULL; /* silence warning */ + int _errno = 0; /* silence warning */ int p_int[2]; int p_in[2]; int p_out[2]; @@ -92,7 +92,7 @@ _exec_oneshot (int si, aa_mode mode) { s->st.event = (is_start) ? AA_EVT_STARTING_FAILED : AA_EVT_STOPPING_FAILED; s->st.code = ERR_WRITE_STATUS; - aa_service_status_set_msg (&s->st, error_str (errno)); + aa_service_status_set_msg (&s->st, strerror (errno)); if (_exec_cb) _exec_cb (si, s->st.event, 0); @@ -206,7 +206,7 @@ _exec_oneshot (int si, aa_mode mode) char * const argv[] = { filename, NULL }; PROG = aa_service_name (s); char buf_e[UINT32_FMT]; - uint32 e; + uint32_t e; selfpipe_finish (); /* Ignore SIGINT to make sure one can ^C to timeout a service without @@ -222,7 +222,7 @@ _exec_oneshot (int si, aa_mode mode) if (fd_move (0, p_in[0]) < 0 || fd_move (1, p_out[1]) < 0 || fd_copy (2, 1) < 0 || fd_move (3, p_prg[1]) < 0) { - e = (uint32) errno; + e = (uint32_t) errno; fd_write (p_int[1], "p", 1); uint32_pack (buf_e, e); fd_write (p_int[1], buf_e, UINT32_FMT); @@ -231,7 +231,7 @@ _exec_oneshot (int si, aa_mode mode) if (chdir (PROG) < 0) { - e = (uint32) errno; + e = (uint32_t) errno; fd_write (p_int[1], "c", 1); uint32_pack (buf_e, e); fd_write (p_int[1], buf_e, UINT32_FMT); @@ -241,7 +241,7 @@ _exec_oneshot (int si, aa_mode mode) buf[l_sn - 1] = '.'; execv (buf + l_sn - 1, argv); /* if it fails... */ - e = (uint32) errno; + e = (uint32_t) errno; fd_write (p_int[1], "e", 1); uint32_pack (buf_e, e); fd_write (p_int[1], buf_e, UINT32_FMT); @@ -272,9 +272,9 @@ _exec_oneshot (int si, aa_mode mode) { char msg[l_fn + 260]; char buf[UINT32_FMT]; - uint32 e = 0; - int p = 0; - int l; + uint32_t e = 0; + size_t p = 0; + size_t l; tain_now_g (); @@ -305,10 +305,10 @@ _exec_oneshot (int si, aa_mode mode) byte_copy (msg + p, l, ": "); p += l; } - l = strlen (error_str (e)); + l = strlen (strerror (e)); if (p + l >= 260) l = 260 - p - 1; - byte_copy (msg + p, l, error_str (e)); + byte_copy (msg + p, l, strerror (e)); p += l; } byte_copy (msg + p, 1, ""); @@ -340,11 +340,11 @@ err: s->st.code = ERR_IO; tain_copynow (&s->st.stamp); { - int l_ft = strlen ("Failed to "); - int l_err = strlen (_err); - int l_buf = strlen (buf); - const char *errstr = error_str (_errno); - int l_es = strlen (errstr); + size_t l_ft = strlen ("Failed to "); + size_t l_err = strlen (_err); + size_t l_buf = strlen (buf); + const char *errstr = strerror (_errno); + size_t l_es = strlen (errstr); char msg[l_ft + l_err + l_buf + 2 + l_es + 1]; byte_copy (msg, l_ft, "Failed to "); diff --git a/src/libanopa/ga_int_list.c b/src/libanopa/ga_int_list.c deleted file mode 100644 index fd84ed4..0000000 --- a/src/libanopa/ga_int_list.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * anopa - Copyright (C) 2015-2017 Olivier Brunel - * - * ga_int_list.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> - * - * This file is part of anopa. - * - * anopa is free software: you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later - * version. - * - * anopa is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * anopa. If not, see http://www.gnu.org/licenses/ - */ - -#include <anopa/ga_int_list.h> - -int -add_to_list (genalloc *list, int si, int check_for_dupes) -{ - if (check_for_dupes) - { - int len = genalloc_len (int, list); - int i; - - for (i = 0; i < len; ++i) - if (list_get (list, i) == si) - return 0; - } - - genalloc_append (int, list, &si); - return 1; -} - -int -remove_from_list (genalloc *list, int si) -{ - int len = genalloc_len (int, list); - int i; - - for (i = 0; i < len; ++i) - if (list_get (list, i) == si) - { - ga_remove (int, list, i); - return 1; - } - - return 0; -} - -int -is_in_list (genalloc *list, int si) -{ - int len = genalloc_len (int, list); - int i; - - for (i = 0; i < len; ++i) - if (list_get (list, i) == si) - return 1; - return 0; -} diff --git a/src/libanopa/ga_list.c b/src/libanopa/ga_list.c new file mode 100644 index 0000000..9544b70 --- /dev/null +++ b/src/libanopa/ga_list.c @@ -0,0 +1,77 @@ +/* + * anopa - Copyright (C) 2015-2016 Olivier Brunel + * + * ga_list.c + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> + * + * This file is part of anopa. + * + * anopa is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * anopa is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * anopa. If not, see http://www.gnu.org/licenses/ + */ + +#include <string.h> +#include <anopa/ga_list.h> + +void +ga_remove (genalloc *ga, size_t size, int i) +{ + size_t len = ga->len / size; + size_t c = len - i - 1; + + if (i < 0 || (size_t) i >= len) + return; + if (c > 0) + memmove (ga->s + (i * size), ga->s + ((i + 1) * size), c * size); + + ga->len -= size; +} + +int +ga_find (genalloc *ga, size_t size, void const *val) +{ + size_t len = ga->len / size; + size_t i; + + for (i = 0; i < len; ++i) + if (memcmp (ga->s + (i * size), val, size) == 0) + return i; + return -1; +} + +int +ga_add_val (genalloc *ga, size_t size, void const *val, int check_for_dupes) +{ + if (check_for_dupes) + { + int i = ga_find (ga, size, val); + + if (i >= 0) + return 0; + } + + stralloc_catb (ga, val, size); + return 1; +} + +int +ga_remove_val (genalloc *ga, size_t size, void const *val) +{ + int i = ga_find (ga, size, val); + + if (i < 0) + return 0; + + ga_remove (ga, size, i); + return 1; +} diff --git a/src/libanopa/output.c b/src/libanopa/output.c index 4d83586..12c9e5c 100644 --- a/src/libanopa/output.c +++ b/src/libanopa/output.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * output.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -48,7 +48,7 @@ aa_set_double_output (int enabled) } void -aa_bb_noflush (int where, const char *s, int len) +aa_bb_noflush (int where, const char *s, size_t len) { putb_noflush (where, s, len); if (double_output) @@ -56,7 +56,7 @@ aa_bb_noflush (int where, const char *s, int len) } void -aa_bb_flush (int where, const char *s, int len) +aa_bb_flush (int where, const char *s, size_t len) { putb_flush (where, s, len); if (double_output) @@ -64,7 +64,7 @@ aa_bb_flush (int where, const char *s, int len) } void -aa_ib_noflush (int where, const char *s, int len) +aa_ib_noflush (int where, const char *s, size_t len) { if (is_tty (where)) putb_noflush (where, s, len); @@ -73,7 +73,7 @@ aa_ib_noflush (int where, const char *s, int len) } void -aa_ib_flush (int where, const char *s, int len) +aa_ib_flush (int where, const char *s, size_t len) { if (is_tty (where)) putb_flush (where, s, len); diff --git a/src/libanopa/progress.c b/src/libanopa/progress.c index 2ecdd5d..bce7039 100644 --- a/src/libanopa/progress.c +++ b/src/libanopa/progress.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * progress.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -21,7 +21,7 @@ */ #include <skalibs/bytestr.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <anopa/progress.h> #include <anopa/output.h> @@ -49,12 +49,12 @@ int aa_progress_update (aa_progress *pg) { char *s; - int skip; - int len; - int rr; + size_t skip; + size_t len; + size_t rr; int cur; int max; - int r; + size_t r; /* sanity: we require at least a NUL byte (for empty msg) */ if (pg->sa.len == 0) @@ -144,10 +144,10 @@ aa_progress_draw (aa_progress *pg, const char *title, int cols, int is_utf8) char buf[UINT_FMT]; unsigned int p1; unsigned int p2; - int w; + size_t w; double d; - int n; - int i; + size_t n; + size_t i; p1 = 100 * pg->pctg; p2 = 10000 * pg->pctg - (100 * p1); @@ -171,7 +171,7 @@ aa_progress_draw (aa_progress *pg, const char *title, int cols, int is_utf8) } /* 7: for "100.0% " 10: margin on the right */ - w = cols - strlen (title) - 1 - 7 - 10; + w = (size_t) cols - strlen (title) - 1 - 7 - 10; if (pg->sa.s[0] != '\0') w -= byte_chr (pg->sa.s, pg->sa.len, '\0'); if (w < 10) diff --git a/src/libanopa/scan_dir.c b/src/libanopa/scan_dir.c index a08a0d6..b655b25 100644 --- a/src/libanopa/scan_dir.c +++ b/src/libanopa/scan_dir.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * scan_dir.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -22,6 +22,7 @@ #define _BSD_SOURCE +#include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <skalibs/direntry.h> @@ -60,12 +61,12 @@ aa_scan_dir (stralloc *sa, int files_only, aa_sd_it_fn iterator, void *data) if (d->d_type == DT_UNKNOWN) { struct stat st; - int l; + size_t l; int rr; l = sa->len; sa->s[l - 1] = '/'; - stralloc_catb (sa, d->d_name, str_len (d->d_name) + 1); + stralloc_catb (sa, d->d_name, strlen (d->d_name) + 1); rr = stat (sa->s, &st); sa->len = l; sa->s[l - 1] = '\0'; diff --git a/src/libanopa/service.c b/src/libanopa/service.c index 6be9e37..dd46578 100644 --- a/src/libanopa/service.c +++ b/src/libanopa/service.c @@ -21,13 +21,14 @@ */ #include <sys/stat.h> +#include <unistd.h> #include <errno.h> #include <skalibs/djbunix.h> /* fd_close() */ #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> #include <skalibs/bytestr.h> #include <skalibs/direntry.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/tai.h> #include <s6/s6-supervise.h> #include <s6/ftrigr.h> @@ -66,12 +67,12 @@ aa_free_services (aa_close_fd_fn _close_fd) genalloc_deepfree (aa_service, &aa_services, free_service); } -int +size_t aa_add_name (const char *name) { - int offset = aa_names.len; + size_t offset = aa_names.len; if (!stralloc_catb (&aa_names, name, strlen (name) + 1)) - return -1; + return (size_t) -1; return offset; } @@ -107,6 +108,8 @@ get_new_service (const char *name) return (errno = ENOTDIR, -ERR_IO); s.offset_name = aa_add_name (name); + if (s.offset_name == (size_t) -1) + return (errno = ENOMEM, -ERR_UNKNOWN); genalloc_append (aa_service, &aa_services, &s); return genalloc_len (aa_service, &aa_services) - 1; } @@ -114,8 +117,8 @@ get_new_service (const char *name) static int get_from_list (genalloc *list, const char *name) { - int l = genalloc_len (int, list); - int i; + size_t l = genalloc_len (int, list); + size_t i; for (i = 0; i < l; ++i) if (!str_diff (name, aa_service_name (aa_service (list_get (list, i))))) @@ -155,7 +158,7 @@ static int contains_fd (const char *filename) { char buf[UINT_FMT + 1]; - int r; + ssize_t r; r = openreadnclose_nb (filename, buf, UINT_FMT); if (r < 0) @@ -165,11 +168,15 @@ contains_fd (const char *filename) return 0; } - buf[byte_chr (buf, r, '\n')] = '\0'; - if (!uint0_scan (buf, &r)) { - aa_strerr_warn2x ("invalid ", filename); - return 0; + unsigned int i = r; + + buf[byte_chr (buf, i, '\n')] = '\0'; + if (!uint0_scan (buf, &i)) + { + aa_strerr_warn2x ("invalid ", filename); + return 0; + } } return 1; @@ -179,7 +186,7 @@ int aa_preload_service (int si) { aa_service_status *svst = &aa_service (si)->st; - int l_sn = strlen (aa_service_name (aa_service (si))); + size_t l_sn = strlen (aa_service_name (aa_service (si))); char buf[l_sn + 1 + sizeof (NOTIFICATION_FILENAME)]; byte_copy (buf, l_sn, aa_service_name (aa_service (si))); @@ -424,8 +431,8 @@ static int check_afters (int si, int *sli, int *has_longrun) { aa_service *s = aa_service (si); - int org = genalloc_len (int, &aa_tmp_list); - int i; + size_t org = genalloc_len (int, &aa_tmp_list); + size_t i; if (s->ls == AA_LOAD_DONE_CHECKED) return 0; @@ -467,7 +474,7 @@ int aa_prepare_mainlist (aa_prepare_cb prepare_cb, aa_exec_cb exec_cb) { int has_longrun = 0; - int i; + size_t i; _exec_cb = exec_cb; aa_tmp_list.len = 0; @@ -491,9 +498,9 @@ aa_prepare_mainlist (aa_prepare_cb prepare_cb, aa_exec_cb exec_cb) */ if (check_afters (si, &sli, &has_longrun) < 0) { - int l; - int j; - int found = 0; + size_t l; + size_t j; + size_t found = 0; add_to_list (&aa_tmp_list, sli, 0); l = genalloc_len (int, &aa_tmp_list); @@ -606,13 +613,13 @@ service_is_ok (aa_mode mode, aa_service *s) void aa_scan_mainlist (aa_scan_cb scan_cb, aa_mode mode) { - int i; + size_t i; for (i = 0; i < genalloc_len (int, &aa_main_list); ) { aa_service *s; int si; - int j; + size_t j; si = list_get (&aa_main_list, i); s = aa_service (si); diff --git a/src/libanopa/service_internal.h b/src/libanopa/service_internal.h index 923fd77..3a0e43e 100644 --- a/src/libanopa/service_internal.h +++ b/src/libanopa/service_internal.h @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * service_internal.h - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -24,6 +24,7 @@ #define AA_SERVICE_INTERNAL_H #include <skalibs/direntry.h> +#include <s6/ftrigr.h> #include <anopa/service.h> extern ftrigr_t _aa_ft; @@ -37,7 +38,7 @@ struct it_data aa_autoload_cb al_cb; }; -extern int _is_valid_service_name (const char *name, int len); +extern int _is_valid_service_name (const char *name, size_t len); extern int _name_start_needs (const char *name, struct it_data *it_data); extern int _it_start_needs (direntry *d, void *data); diff --git a/src/libanopa/service_name.c b/src/libanopa/service_name.c index 7a42a26..3a8fd1f 100644 --- a/src/libanopa/service_name.c +++ b/src/libanopa/service_name.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * service_name.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -21,13 +21,14 @@ */ #include <skalibs/bytestr.h> +#include "service_internal.h" int -_is_valid_service_name (const char *name, int len) +_is_valid_service_name (const char *name, size_t len) { - int r; + size_t r; - if (len <= 0) + if (len == 0) return 0; if (name[0] == '.') return 0; diff --git a/src/libanopa/service_start.c b/src/libanopa/service_start.c index 145ee13..d24896b 100644 --- a/src/libanopa/service_start.c +++ b/src/libanopa/service_start.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * service_start.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -21,6 +21,7 @@ */ #include <skalibs/direntry.h> +#include <skalibs/bytestr.h> #include <anopa/service.h> #include <anopa/ga_int_list.h> #include <anopa/err.h> @@ -32,7 +33,7 @@ void aa_unmark_service (int si) { aa_service *s = aa_service (si); - int i; + size_t i; if (--s->nb_mark > 0) return; @@ -91,16 +92,16 @@ _name_start_needs (const char *name, struct it_data *it_data) else if (r < 0) { aa_service *s = aa_service (it_data->si); - int l = genalloc_len (int, &s->needs); - int i; + size_t l = genalloc_len (int, &s->needs); + size_t i; for (i = 0; i < l; ++i) aa_unmark_service (list_get (&s->needs, i)); if (!(it_data->mode & AA_MODE_IS_DRY)) { - int l_n = strlen (name); - int l_em = strlen (errmsg[-r]); + size_t l_n = strlen (name); + size_t l_em = strlen (errmsg[-r]); char buf[l_n + 2 + l_em + 1]; byte_copy (buf, l_n, name); diff --git a/src/libanopa/service_status.c b/src/libanopa/service_status.c index 476533f..f201ea1 100644 --- a/src/libanopa/service_status.c +++ b/src/libanopa/service_status.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * service_status.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -26,7 +26,7 @@ #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> #include <skalibs/bytestr.h> -#include <skalibs/uint32.h> +#include <skalibs/types.h> #include <skalibs/tai.h> #include <anopa/service_status.h> @@ -40,9 +40,9 @@ aa_service_status_free (aa_service_status *svst) int aa_service_status_read (aa_service_status *svst, const char *dir) { - unsigned int len = strlen (dir); + size_t len = strlen (dir); char file[len + 1 + sizeof (AA_SVST_FILENAME)]; - uint32 u; + uint32_t u; /* most cases should be w/out a message, so we'll only need FIXED_SIZE and * one extra byte to NUL-terminate the (empty) message */ @@ -80,7 +80,7 @@ aa_service_status_read (aa_service_status *svst, const char *dir) int aa_service_status_write (aa_service_status *svst, const char *dir) { - unsigned int len = strlen (dir); + size_t len = strlen (dir); char file[len + 1 + sizeof (AA_SVST_FILENAME)]; mode_t mask; int r; @@ -90,8 +90,8 @@ aa_service_status_write (aa_service_status *svst, const char *dir) return -1; tain_pack (svst->sa.s, &svst->stamp); - uint32_pack (svst->sa.s + 12, (uint32) svst->event); - uint32_pack (svst->sa.s + 16, (uint32) svst->code); + uint32_pack (svst->sa.s + 12, (uint32_t) svst->event); + uint32_pack (svst->sa.s + 16, (uint32_t) svst->code); if (svst->sa.len < AA_SVST_FIXED_SIZE) svst->sa.len = AA_SVST_FIXED_SIZE; @@ -115,7 +115,7 @@ aa_service_status_write (aa_service_status *svst, const char *dir) int aa_service_status_set_msg (aa_service_status *svst, const char *msg) { - int len; + size_t len; len = strlen (msg); if (len > AA_SVST_MAX_MSG_SIZE) diff --git a/src/libanopa/services.c b/src/libanopa/services.c index a1185c4..7200662 100644 --- a/src/libanopa/services.c +++ b/src/libanopa/services.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * services.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -29,7 +29,7 @@ genalloc aa_services = GENALLOC_ZERO; stralloc aa_names = STRALLOC_ZERO; genalloc aa_main_list = GENALLOC_ZERO; genalloc aa_tmp_list = GENALLOC_ZERO; -int aa_secs_timeout = 0; +unsigned int aa_secs_timeout = 0; ftrigr_t _aa_ft = FTRIGR_ZERO; aa_exec_cb _exec_cb = NULL; diff --git a/src/libanopa/stats.c b/src/libanopa/stats.c index 8a37244..fa6377f 100644 --- a/src/libanopa/stats.c +++ b/src/libanopa/stats.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * stats.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -20,11 +20,11 @@ * anopa. If not, see http://www.gnu.org/licenses/ */ -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/buffer.h> #include <skalibs/genalloc.h> #include <anopa/output.h> -#include <anopa/ga_int_list.h> +#include <anopa/ga_list.h> void aa_show_stat_nb (int nb, const char *title, const char *ansi_color) @@ -51,18 +51,18 @@ aa_show_stat_names (const char *names, const char *title, const char *ansi_color) { - int i; + size_t i; - if (genalloc_len (int, ga_offets) <= 0) + if (genalloc_len (size_t, ga_offets) <= 0) return; aa_put_title (0, title, "", 0); - for (i = 0; i < genalloc_len (int, ga_offets); ++i) + for (i = 0; i < genalloc_len (size_t, ga_offets); ++i) { if (i > 0) aa_bs_noflush (AA_OUT, "; "); aa_is_noflush (AA_OUT, ansi_color); - aa_bs_noflush (AA_OUT, names + list_get (ga_offets, i)); + aa_bs_noflush (AA_OUT, names + ga_get (size_t, ga_offets, i)); aa_is_noflush (AA_OUT, ANSI_HIGHLIGHT_ON); } aa_end_title (); diff --git a/src/utils/aa-ctty.c b/src/utils/aa-ctty.c index 9ee4ed2..746bcf8 100644 --- a/src/utils/aa-ctty.c +++ b/src/utils/aa-ctty.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-ctty.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -23,7 +23,7 @@ #include <getopt.h> #include <termios.h> #include <sys/ioctl.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <skalibs/djbunix.h> #include <anopa/common.h> #include <anopa/output.h> @@ -69,7 +69,7 @@ main (int argc, char * const argv[], char const * const *envp) break; case 'f': - if (!uint0_scan (optarg, &fd)) + if (!uint0_scan (optarg, (unsigned int *) &fd)) aa_strerr_diefu1sys (1, "set fd"); break; diff --git a/src/utils/aa-incmdline.c b/src/utils/aa-incmdline.c index 17da663..127331d 100644 --- a/src/utils/aa-incmdline.c +++ b/src/utils/aa-incmdline.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-incmdline.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -51,9 +51,9 @@ main (int argc, char * const argv[]) int quiet = 0; int req = 0; char safe = '\0'; - int len_arg; - int start; - int i; + size_t len_arg; + size_t start; + size_t i; for (;;) { @@ -125,7 +125,7 @@ main (int argc, char * const argv[]) || sa.s[i] == '\n' || sa.s[i] == '\0') { int found = (i - start == len_arg && !str_diffn (sa.s + start, argv[0], len_arg)); - int len; + size_t len; if (sa.s[i] != '=') { diff --git a/src/utils/aa-kill.c b/src/utils/aa-kill.c index f870053..62fd4c7 100644 --- a/src/utils/aa-kill.c +++ b/src/utils/aa-kill.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-kill.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -28,7 +28,8 @@ #include <skalibs/sig.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> -#include <skalibs/uint.h> +#include <skalibs/bytestr.h> +#include <skalibs/types.h> #include <anopa/common.h> #include <anopa/output.h> #include <anopa/scan_dir.h> @@ -68,8 +69,8 @@ it_kill (direntry *d, void *data) { stralloc *sa = data; char c; - int l; - int r; + size_t l; + ssize_t r; /* ignore files, not-number dirs, PID 1 and ourself */ if (d->d_type != DT_DIR || *d->d_name < '1' || *d->d_name > '9' @@ -95,8 +96,6 @@ it_kill (direntry *d, void *data) if (!uint_scan (d->d_name, &u)) goto done; pid = (pid_t) u; - if (pid != u) - goto done; if (send.hup) _kill (pid, SIGHUP); if (send.term) diff --git a/src/utils/aa-mount.c b/src/utils/aa-mount.c index 376d022..f9be8c1 100644 --- a/src/utils/aa-mount.c +++ b/src/utils/aa-mount.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-mount.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -26,6 +26,7 @@ #include <sys/types.h> #include <sys/mount.h> #include <skalibs/stralloc.h> +#include <skalibs/bytestr.h> #include <anopa/common.h> #include <anopa/output.h> #include "mount-constants.h" @@ -33,7 +34,7 @@ struct mnt_opt { const char *name; - unsigned int len; + size_t len; unsigned long value; enum { OP_ADD, @@ -75,12 +76,12 @@ add_option (stralloc *sa, unsigned long *flags, char const *options) mnt_opt ("sync", ADD, MS_SYNCHRONOUS) }; #undef mnt_opt - unsigned int nb = sizeof (mnt_options) / sizeof (*mnt_options); + size_t nb = sizeof (mnt_options) / sizeof (*mnt_options); for (;;) { - unsigned int e; - unsigned int i; + size_t e; + size_t i; e = str_chr (options, ','); for (i = 0; i < nb; ++i) diff --git a/src/utils/aa-mvlog.c b/src/utils/aa-mvlog.c index fba0d50..50c4013 100644 --- a/src/utils/aa-mvlog.c +++ b/src/utils/aa-mvlog.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-mvlog.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -86,7 +86,7 @@ main (int argc, char * const argv[]) aa_strerr_dief2x (2, argv[0], ": not a file"); { - int l = strlen (argv[1]); + size_t l = strlen (argv[1]); char newname[l + 27]; char target[26]; diff --git a/src/utils/aa-service.c b/src/utils/aa-service.c index 87612d2..4635949 100644 --- a/src/utils/aa-service.c +++ b/src/utils/aa-service.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-service.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -64,7 +64,7 @@ addvar (const char *name, const char *value, exlsn_t *info) if (el_vardupl (name, info->vars.s, info->vars.len)) return -ERR_BAD_KEY; - if (!stralloc_catb (&info->vars, name, str_len (name) + 1)) + if (!stralloc_catb (&info->vars, name, strlen (name) + 1)) return -ERR_ADDVAR; if (!stralloc_cats (&info->values, value)) goto err; @@ -94,9 +94,9 @@ aa_service (exlsn_t *info) { stralloc sa = STRALLOC_ZERO; char *s; - unsigned int len; + size_t len; + size_t n; int r; - int n; if (sagetcwd (&sa) < 0) return -ERR_DIRNAME; @@ -141,7 +141,7 @@ aa_service (exlsn_t *info) if (r < 0) goto err; - len = str_len (s); + len = strlen (s); n = byte_chr (s, len, '@'); if (n < len) s[n] = '\0'; diff --git a/src/utils/aa-setready.c b/src/utils/aa-setready.c index 637ec8d..f8e2eb8 100644 --- a/src/utils/aa-setready.c +++ b/src/utils/aa-setready.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-setready.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -24,6 +24,7 @@ #include <errno.h> #include <unistd.h> #include <skalibs/djbunix.h> +#include <skalibs/bytestr.h> #include <s6/ftrigw.h> #include <s6/s6-supervise.h> #include <anopa/common.h> @@ -94,7 +95,7 @@ main (int argc, char * const argv[]) dieusage (1); { - int l = strlen (argv[0]); + size_t l = strlen (argv[0]); char fifodir[l + 1 + sizeof (S6_SUPERVISE_EVENTDIR)]; s6_svstatus_t st6 = S6_SVSTATUS_ZERO; diff --git a/src/utils/aa-terminate.c b/src/utils/aa-terminate.c index c19e1e7..e274695 100644 --- a/src/utils/aa-terminate.c +++ b/src/utils/aa-terminate.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-terminate.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -25,8 +25,11 @@ #include <getopt.h> #include <stdio.h> #include <mntent.h> +#include <strings.h> #include <errno.h> #include <sys/mount.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <sys/swap.h> #include <string.h> @@ -35,7 +38,7 @@ #include <linux/loop.h> #include <skalibs/djbunix.h> #include <skalibs/stralloc.h> -#include <skalibs/error.h> +#include <skalibs/bytestr.h> #include <anopa/common.h> #include <anopa/scan_dir.h> #include <anopa/output.h> @@ -60,7 +63,7 @@ verbose_fail (int e) if (level < 2) return; aa_bs_noflush (AA_OUT, "Failed: "); - aa_bs_noflush (AA_OUT, error_str (e)); + aa_bs_noflush (AA_OUT, strerror (e)); aa_bs_flush (AA_OUT, "\n"); } @@ -156,11 +159,11 @@ static int do_work (stralloc *sa, do_fn do_it) { int did = 0; - int i; + size_t i; for (i = 0; i < sa->len; ) { - int l; + size_t l; l = strlen (sa->s + i) + 1; if (do_it (sa->s + i) < 0) @@ -182,7 +185,7 @@ it_loops_dms (direntry *d, void *data) { stralloc **sas = data; int i; - int l; + size_t l; if (d->d_type != DT_BLK) return 0; @@ -228,11 +231,11 @@ it_loops_dms (direntry *d, void *data) static void show_left (const char *prefix, stralloc *sa) { - int i; + size_t i; for (i = 0; i < sa->len; ) { - int l; + size_t l; l = strlen (sa->s + i) + 1; aa_put_warn (prefix, sa->s +i, 1); @@ -347,12 +350,12 @@ again: if (sa.len > 0) { - int l; + size_t l; l = byte_chr (sa.s, sa.len, '\n') + 1; for ( ; l < sa.len; ) { - int e; + size_t e; /* FIXME: how are spaces-in-filename treated? */ e = byte_chr (sa.s + l, sa.len - l, ' '); diff --git a/src/utils/aa-test.c b/src/utils/aa-test.c index fb76108..bcb3911 100644 --- a/src/utils/aa-test.c +++ b/src/utils/aa-test.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-test.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -24,7 +24,7 @@ #include <errno.h> #include <unistd.h> #include <sys/stat.h> -#include <skalibs/uint.h> +#include <skalibs/types.h> #include <anopa/common.h> #include <anopa/output.h> @@ -76,9 +76,9 @@ main (int argc, char * const argv[]) PROG = "aa-test"; struct stat st; uid_t euid; - int mode; + int mode = 0; /* silence warning */ char test = 0; - int repeat = -1; + unsigned int repeat = 0; for (;;) { @@ -130,7 +130,9 @@ main (int argc, char * const argv[]) if (optarg && !uint0_scan (optarg, &repeat)) aa_strerr_diefu2sys (1, "set repeat counter to ", optarg); else if (!optarg) - repeat = 0; + repeat = 1; + else + ++repeat; break; case 'V': @@ -146,19 +148,16 @@ main (int argc, char * const argv[]) if (argc != 1 || test == 0) dieusage (1); - if (repeat > 0) - ++repeat; - again: if (lstat (argv[0], &st) < 0) { if (errno != ENOENT) aa_strerr_diefu2sys (2, "stat ", argv[0]); - else if (repeat >= 0) + else if (repeat >= 1) { - if (repeat > 1) + if (repeat > 2) --repeat; - else if (repeat == 1) + else if (repeat == 2) return 3; sleep (1); goto again; diff --git a/src/utils/aa-tty.c b/src/utils/aa-tty.c index 8ce8dfa..e5af583 100644 --- a/src/utils/aa-tty.c +++ b/src/utils/aa-tty.c @@ -2,7 +2,7 @@ * anopa - Copyright (C) 2015-2017 Olivier Brunel * * aa-tty.c - * Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com> + * Copyright (C) 2015-2017 Olivier Brunel <jjk@jjacky.com> * * This file is part of anopa. * @@ -45,10 +45,10 @@ main (int argc, char * const argv[]) { PROG = "aa-tty"; char file[256]; - int max = sizeof (file) - sizeof (PREFIX) - sizeof (NAME) + 1; + size_t max = sizeof (file) - sizeof (PREFIX) - sizeof (NAME) + 1; char name[max]; - int skip; - int r; + size_t skip; + ssize_t r; for (;;) { @@ -93,13 +93,13 @@ main (int argc, char * const argv[]) aa_strerr_diefu2sys (2, "read ", file); /* last entry is the active one */ skip = byte_rchr (name, r, ' ') + 1; - if (skip > r) + if (skip > (size_t) r) skip = 0; for (;;) { const char *s = name + skip; - int l = r - skip; + size_t l = r - skip; byte_copy (file + sizeof (PREFIX) - 1, l, s); byte_copy (file + sizeof (PREFIX) - 2 + l, sizeof (NAME), NAME);