diff --git a/api.c b/api.c index ee2354d8..8d4959fe 100644 --- a/api.c +++ b/api.c @@ -22,7 +22,6 @@ */ #include -#include #include #include #include @@ -44,28 +43,6 @@ uev_t api_watcher; -/* Allowed characters in job/id/name */ -static int isallowed(int ch) -{ - return isprint(ch); -} - -/* Sanitize user input, make sure to NUL terminate. */ -static char *sanitize(char *arg, size_t len) -{ - size_t i = 0; - - while (isallowed(arg[i]) && i < len) - i++; - - if (i + 1 < len) { - arg[i + 1] = 0; - return arg; - } - - return NULL; -} - static int call(int (*action)(svc_t *), char *buf, size_t len) { int result = 0; diff --git a/util.c b/util.c index fd97c73e..7f98d17c 100644 --- a/util.c +++ b/util.c @@ -21,6 +21,7 @@ * THE SOFTWARE. */ +#include /* isprint() */ #include #include @@ -43,6 +44,30 @@ void do_sleep(unsigned int sec) ; } +/* Allowed characters in job/id/name */ +static int isallowed(int ch) +{ + return isprint(ch); +} + +/* Sanitize user input, make sure to NUL terminate. */ +char *sanitize(char *arg, size_t len) +{ + size_t i = 0; + + while (isallowed(arg[i]) && i < len) + i++; + + if (i + 1 < len) { + arg[i + 1] = 0; + return arg; + } + + if (i > 1 && arg[i] == 0) + return arg; + + return NULL; +} /** * Local Variables: diff --git a/util.h b/util.h index 9aefd2b2..ef522415 100644 --- a/util.h +++ b/util.h @@ -28,6 +28,7 @@ extern char *prognm; char *progname(char *arg0); void do_sleep(unsigned int sec); +char *sanitize(char *arg, size_t len); #endif /* FINIT_UTIL_H_ */