Introduce cbasename so we don't have to strdup(basename) and free all the time.
This commit is contained in:
parent
2f7218c984
commit
cd45e54357
@ -29,6 +29,7 @@ static void usage (int exit_status)
|
|||||||
{
|
{
|
||||||
const char * const has_arg[] = { "", "<arg>", "[arg]" };
|
const char * const has_arg[] = { "", "<arg>", "[arg]" };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf ("Usage: %s [options] ", applet);
|
printf ("Usage: %s [options] ", applet);
|
||||||
#ifdef extraopts
|
#ifdef extraopts
|
||||||
printf (extraopts);
|
printf (extraopts);
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define APPLET "checkown"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -48,7 +46,7 @@
|
|||||||
#include "einfo.h"
|
#include "einfo.h"
|
||||||
#include "rc-misc.h"
|
#include "rc-misc.h"
|
||||||
|
|
||||||
static char *applet = NULL;
|
static const char *applet;
|
||||||
|
|
||||||
static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, int file)
|
static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, int file)
|
||||||
{
|
{
|
||||||
@ -189,10 +187,9 @@ int checkown (int argc, char **argv)
|
|||||||
struct group *gr = NULL;
|
struct group *gr = NULL;
|
||||||
bool file = 0;
|
bool file = 0;
|
||||||
|
|
||||||
|
applet = cbasename (argv[0]);
|
||||||
int retval = EXIT_SUCCESS;
|
int retval = EXIT_SUCCESS;
|
||||||
|
|
||||||
applet = argv[0];
|
|
||||||
|
|
||||||
while ((opt = getopt_long (argc, argv, getoptstring,
|
while ((opt = getopt_long (argc, argv, getoptstring,
|
||||||
longopts, (int *) 0)) != -1)
|
longopts, (int *) 0)) != -1)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -87,7 +86,7 @@ static struct mntent *getmntfile (const char *file)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *applet;
|
static const char *applet = NULL;
|
||||||
|
|
||||||
#include "_usage.h"
|
#include "_usage.h"
|
||||||
#define getoptstring "bmop:t:" getoptstring_COMMON
|
#define getoptstring "bmop:t:" getoptstring_COMMON
|
||||||
@ -129,7 +128,7 @@ int fstabinfo (int argc, char **argv)
|
|||||||
char *file;
|
char *file;
|
||||||
bool filtered = false;
|
bool filtered = false;
|
||||||
|
|
||||||
applet = basename (argv[0]);
|
applet = cbasename (argv[0]);
|
||||||
|
|
||||||
/* Ensure that we are only quiet when explicitly told to be */
|
/* Ensure that we are only quiet when explicitly told to be */
|
||||||
unsetenv ("EINFO_QUIET");
|
unsetenv ("EINFO_QUIET");
|
||||||
|
@ -313,7 +313,6 @@ bool rc_service_daemon_set (const char *service, const char *exec,
|
|||||||
const char *name, const char *pidfile,
|
const char *name, const char *pidfile,
|
||||||
bool started)
|
bool started)
|
||||||
{
|
{
|
||||||
char *svc;
|
|
||||||
char *dirpath;
|
char *dirpath;
|
||||||
char *file = NULL;
|
char *file = NULL;
|
||||||
int i;
|
int i;
|
||||||
@ -330,10 +329,9 @@ bool rc_service_daemon_set (const char *service, const char *exec,
|
|||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
svc = xstrdup (service);
|
|
||||||
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons",
|
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons",
|
||||||
basename (svc), (char *) NULL);
|
cbasename (service), (char *) NULL);
|
||||||
free (svc);
|
|
||||||
|
|
||||||
if (exec) {
|
if (exec) {
|
||||||
i = strlen (exec) + 6;
|
i = strlen (exec) + 6;
|
||||||
@ -417,17 +415,14 @@ bool rc_service_started_daemon (const char *service, const char *exec,
|
|||||||
int i;
|
int i;
|
||||||
char *mexec;
|
char *mexec;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
char *svc;
|
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
|
|
||||||
if (! service || ! exec)
|
if (! service || ! exec)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", cbasename (service),
|
||||||
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
|
|
||||||
i = strlen (exec) + 6;
|
i = strlen (exec) + 6;
|
||||||
mexec = xmalloc (sizeof (char) * i);
|
mexec = xmalloc (sizeof (char) * i);
|
||||||
@ -474,15 +469,12 @@ bool rc_service_daemons_crashed (const char *service)
|
|||||||
char *p;
|
char *p;
|
||||||
char *token;
|
char *token;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
char *svc;
|
|
||||||
|
|
||||||
if (! service)
|
if (! service)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", cbasename (service),
|
||||||
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
|
|
||||||
if (! (dp = opendir (dirpath))) {
|
if (! (dp = opendir (dirpath))) {
|
||||||
free (dirpath);
|
free (dirpath);
|
||||||
|
57
src/librc.c
57
src/librc.c
@ -378,15 +378,12 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel)
|
|||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
bool retval;
|
bool retval;
|
||||||
char *svc;
|
|
||||||
|
|
||||||
if (! runlevel || ! service)
|
if (! runlevel || ! service)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, cbasename (service),
|
||||||
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
retval = exists (file);
|
retval = exists (file);
|
||||||
free (file);
|
free (file);
|
||||||
|
|
||||||
@ -399,21 +396,18 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
|||||||
char *file;
|
char *file;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int skip_state = -1;
|
int skip_state = -1;
|
||||||
char *base;
|
const char *base;
|
||||||
char *svc;
|
|
||||||
char *init = rc_service_resolve (service);
|
char *init = rc_service_resolve (service);
|
||||||
bool skip_wasinactive = false;
|
bool skip_wasinactive = false;
|
||||||
|
|
||||||
if (! service)
|
if (! init)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
base = cbasename (service);
|
||||||
base = basename (svc);
|
|
||||||
|
|
||||||
if (state != RC_SERVICE_STOPPED) {
|
if (state != RC_SERVICE_STOPPED) {
|
||||||
if (! exists (init)) {
|
if (! exists (init)) {
|
||||||
free (init);
|
free (init);
|
||||||
free (svc);
|
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,7 +419,6 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
|||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
free (file);
|
free (file);
|
||||||
free (init);
|
free (init);
|
||||||
free (svc);
|
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +428,6 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
|||||||
|
|
||||||
if (state == RC_SERVICE_COLDPLUGGED || state == RC_SERVICE_FAILED) {
|
if (state == RC_SERVICE_COLDPLUGGED || state == RC_SERVICE_FAILED) {
|
||||||
free (init);
|
free (init);
|
||||||
free (svc);
|
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,7 +441,7 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
|||||||
s != RC_SERVICE_SCHEDULED) &&
|
s != RC_SERVICE_SCHEDULED) &&
|
||||||
(! skip_wasinactive || s != RC_SERVICE_WASINACTIVE))
|
(! skip_wasinactive || s != RC_SERVICE_WASINACTIVE))
|
||||||
{
|
{
|
||||||
file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state(s), base,
|
file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (s), base,
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
if (exists (file)) {
|
if (exists (file)) {
|
||||||
if ((state == RC_SERVICE_STARTING ||
|
if ((state == RC_SERVICE_STARTING ||
|
||||||
@ -516,7 +508,6 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
|||||||
free (sdir);
|
free (sdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (svc);
|
|
||||||
free (init);
|
free (init);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
@ -526,11 +517,10 @@ rc_service_state_t rc_service_state (const char *service)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int state = RC_SERVICE_STOPPED;
|
int state = RC_SERVICE_STOPPED;
|
||||||
char *svc = xstrdup (service);
|
|
||||||
|
|
||||||
for (i = 0; rc_service_state_names[i].name; i++) {
|
for (i = 0; rc_service_state_names[i].name; i++) {
|
||||||
char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name,
|
char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name,
|
||||||
basename (svc), (char*) NULL);
|
cbasename (service), (char*) NULL);
|
||||||
if (exists (file)) {
|
if (exists (file)) {
|
||||||
if (rc_service_state_names[i].state <= 0x10)
|
if (rc_service_state_names[i].state <= 0x10)
|
||||||
state = rc_service_state_names[i].state;
|
state = rc_service_state_names[i].state;
|
||||||
@ -539,7 +529,6 @@ rc_service_state_t rc_service_state (const char *service)
|
|||||||
}
|
}
|
||||||
free (file);
|
free (file);
|
||||||
}
|
}
|
||||||
free (svc);
|
|
||||||
|
|
||||||
if (state & RC_SERVICE_STOPPED) {
|
if (state & RC_SERVICE_STOPPED) {
|
||||||
char **services = rc_services_scheduled_by (service);
|
char **services = rc_services_scheduled_by (service);
|
||||||
@ -603,7 +592,6 @@ static pid_t _exec_service (const char *service, const char *arg)
|
|||||||
char *file;
|
char *file;
|
||||||
char *fifo;
|
char *fifo;
|
||||||
pid_t pid = -1;
|
pid_t pid = -1;
|
||||||
char *svc;
|
|
||||||
|
|
||||||
file = rc_service_resolve (service);
|
file = rc_service_resolve (service);
|
||||||
if (! exists (file)) {
|
if (! exists (file)) {
|
||||||
@ -613,10 +601,8 @@ static pid_t _exec_service (const char *service, const char *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We create a fifo so that other services can wait until we complete */
|
/* We create a fifo so that other services can wait until we complete */
|
||||||
svc = xstrdup (service);
|
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", cbasename (service),
|
||||||
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
|
|
||||||
if (mkfifo (fifo, 0600) != 0 && errno != EEXIST) {
|
if (mkfifo (fifo, 0600) != 0 && errno != EEXIST) {
|
||||||
free (fifo);
|
free (fifo);
|
||||||
@ -674,26 +660,21 @@ bool rc_service_schedule_start (const char *service,
|
|||||||
char *dir;
|
char *dir;
|
||||||
char *init;
|
char *init;
|
||||||
char *file;
|
char *file;
|
||||||
char *svc;
|
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
/* service may be a provided service, like net */
|
/* service may be a provided service, like net */
|
||||||
if (! service || ! rc_service_exists (service_to_start))
|
if (! service || ! rc_service_exists (service_to_start))
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", cbasename (service),
|
||||||
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
if (mkdir (dir, 0755) != 0 && errno != EEXIST) {
|
if (mkdir (dir, 0755) != 0 && errno != EEXIST) {
|
||||||
free (dir);
|
free (dir);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
init = rc_service_resolve (service_to_start);
|
init = rc_service_resolve (service_to_start);
|
||||||
svc = xstrdup (service_to_start);
|
file = rc_strcatpaths (dir, cbasename (service_to_start), (char *) NULL);
|
||||||
file = rc_strcatpaths (dir, basename (svc), (char *) NULL);
|
|
||||||
free (svc);
|
|
||||||
retval = (exists (file) || symlink (init, file) == 0);
|
retval = (exists (file) || symlink (init, file) == 0);
|
||||||
free (init);
|
free (init);
|
||||||
free (file);
|
free (file);
|
||||||
@ -705,12 +686,10 @@ librc_hidden_def(rc_service_schedule_start)
|
|||||||
|
|
||||||
bool rc_service_schedule_clear (const char *service)
|
bool rc_service_schedule_clear (const char *service)
|
||||||
{
|
{
|
||||||
char *svc = xstrdup (service);
|
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", cbasename (service),
|
||||||
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
free (svc);
|
|
||||||
if (! (retval = rm_dir (dir, true)) && errno == ENOENT)
|
if (! (retval = rm_dir (dir, true)) && errno == ENOENT)
|
||||||
retval = true;
|
retval = true;
|
||||||
free (dir);
|
free (dir);
|
||||||
@ -787,7 +766,6 @@ bool rc_service_add (const char *runlevel, const char *service)
|
|||||||
bool retval;
|
bool retval;
|
||||||
char *init;
|
char *init;
|
||||||
char *file;
|
char *file;
|
||||||
char *svc;
|
|
||||||
|
|
||||||
if (! rc_runlevel_exists (runlevel)) {
|
if (! rc_runlevel_exists (runlevel)) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
@ -814,10 +792,8 @@ bool rc_service_add (const char *runlevel, const char *service)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
svc = xstrdup (service);
|
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, cbasename (service),
|
||||||
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
retval = (symlink (init, file) == 0);
|
retval = (symlink (init, file) == 0);
|
||||||
free (init);
|
free (init);
|
||||||
free (file);
|
free (file);
|
||||||
@ -828,16 +804,13 @@ librc_hidden_def(rc_service_add)
|
|||||||
bool rc_service_delete (const char *runlevel, const char *service)
|
bool rc_service_delete (const char *runlevel, const char *service)
|
||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
char *svc;
|
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
if (! runlevel || ! service)
|
if (! runlevel || ! service)
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
svc = xstrdup (service);
|
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, cbasename (service),
|
||||||
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
free (svc);
|
|
||||||
if (unlink (file) == 0)
|
if (unlink (file) == 0)
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
@ -868,19 +841,17 @@ librc_hidden_def(rc_services_scheduled_by)
|
|||||||
|
|
||||||
char **rc_services_scheduled (const char *service)
|
char **rc_services_scheduled (const char *service)
|
||||||
{
|
{
|
||||||
char *svc = xstrdup (service);
|
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", cbasename (service),
|
||||||
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
|
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
char **list = NULL;
|
char **list = NULL;
|
||||||
|
|
||||||
free (svc);
|
|
||||||
list = ls_dir (dir, LS_INITD);
|
list = ls_dir (dir, LS_INITD);
|
||||||
free (dir);
|
free (dir);
|
||||||
return (list);
|
return (list);
|
||||||
}
|
}
|
||||||
librc_hidden_def(rc_services_scheduled)
|
librc_hidden_def(rc_services_scheduled)
|
||||||
|
|
||||||
bool rc_service_plugable (char *service)
|
bool rc_service_plugable (const char *service)
|
||||||
{
|
{
|
||||||
char *list;
|
char *list;
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -367,8 +366,6 @@ int mountinfo (int argc, char **argv)
|
|||||||
int result;
|
int result;
|
||||||
bool quiet;
|
bool quiet;
|
||||||
|
|
||||||
applet = basename (argv[0]);
|
|
||||||
|
|
||||||
/* Ensure that we are only quiet when explicitly told to be */
|
/* Ensure that we are only quiet when explicitly told to be */
|
||||||
unsetenv ("EINFO_QUIET");
|
unsetenv ("EINFO_QUIET");
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define APPLET "rc-depend"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@ -47,6 +45,8 @@
|
|||||||
#include "rc-misc.h"
|
#include "rc-misc.h"
|
||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
|
|
||||||
|
static const char *applet;
|
||||||
|
|
||||||
rc_depinfo_t *_rc_deptree_load (int *regen) {
|
rc_depinfo_t *_rc_deptree_load (int *regen) {
|
||||||
if (rc_deptree_update_needed ()) {
|
if (rc_deptree_update_needed ()) {
|
||||||
int retval;
|
int retval;
|
||||||
@ -62,8 +62,6 @@ rc_depinfo_t *_rc_deptree_load (int *regen) {
|
|||||||
return (rc_deptree_load ());
|
return (rc_deptree_load ());
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *applet = NULL;
|
|
||||||
|
|
||||||
#include "_usage.h"
|
#include "_usage.h"
|
||||||
#define getoptstring "t:suT" getoptstring_COMMON
|
#define getoptstring "t:suT" getoptstring_COMMON
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
@ -98,7 +96,7 @@ int rc_depend (int argc, char **argv)
|
|||||||
int opt;
|
int opt;
|
||||||
char *token;
|
char *token;
|
||||||
|
|
||||||
applet = argv[0];
|
applet = cbasename (argv[0]);
|
||||||
|
|
||||||
while ((opt = getopt_long (argc, argv, getoptstring,
|
while ((opt = getopt_long (argc, argv, getoptstring,
|
||||||
longopts, (int *) 0)) != -1)
|
longopts, (int *) 0)) != -1)
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef LIB
|
#ifndef LIB
|
||||||
# define LIB "lib"
|
# define LIB "lib"
|
||||||
@ -118,4 +119,14 @@ bool rc_conf_yesno (const char *var);
|
|||||||
char **env_filter (void);
|
char **env_filter (void);
|
||||||
char **env_config (void);
|
char **env_config (void);
|
||||||
|
|
||||||
|
/* cbasename never modifies the argument. As such, if there is a trailing
|
||||||
|
* slash then an empty string is returned. */
|
||||||
|
static inline const char *cbasename (const char *argv0) {
|
||||||
|
char *l = strrchr (argv0, '/');
|
||||||
|
|
||||||
|
if (l)
|
||||||
|
return (++l);
|
||||||
|
return (argv0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define APPLET "rc-update"
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -46,7 +44,7 @@
|
|||||||
#include "rc-misc.h"
|
#include "rc-misc.h"
|
||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
|
|
||||||
static char *applet = NULL;
|
static const char *applet = NULL;
|
||||||
|
|
||||||
/* Return the number of changes made:
|
/* Return the number of changes made:
|
||||||
* -1 = no changes (error)
|
* -1 = no changes (error)
|
||||||
@ -161,7 +159,7 @@ int rc_update (int argc, char **argv)
|
|||||||
int opt;
|
int opt;
|
||||||
int retval = EXIT_FAILURE;
|
int retval = EXIT_FAILURE;
|
||||||
|
|
||||||
applet = argv[0];
|
applet = cbasename (argv[0]);
|
||||||
|
|
||||||
while ((opt = getopt_long (argc, argv, getoptstring,
|
while ((opt = getopt_long (argc, argv, getoptstring,
|
||||||
longopts, (int *) 0)) != -1)
|
longopts, (int *) 0)) != -1)
|
||||||
|
12
src/rc.c
12
src/rc.c
@ -36,8 +36,6 @@
|
|||||||
|
|
||||||
const char copyright[] = "Copyright (c) 2007 Roy Marples";
|
const char copyright[] = "Copyright (c) 2007 Roy Marples";
|
||||||
|
|
||||||
#define APPLET "rc"
|
|
||||||
|
|
||||||
#define SYSLOG_NAMES
|
#define SYSLOG_NAMES
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -49,7 +47,6 @@ const char copyright[] = "Copyright (c) 2007 Roy Marples";
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -93,7 +90,7 @@ extern char **environ;
|
|||||||
static char *RUNLEVEL = NULL;
|
static char *RUNLEVEL = NULL;
|
||||||
static char *PREVLEVEL = NULL;
|
static char *PREVLEVEL = NULL;
|
||||||
|
|
||||||
static char *applet = NULL;
|
static const char *applet = NULL;
|
||||||
static char *runlevel = NULL;
|
static char *runlevel = NULL;
|
||||||
static char **env = NULL;
|
static char **env = NULL;
|
||||||
static char **newenv = NULL;
|
static char **newenv = NULL;
|
||||||
@ -150,9 +147,6 @@ static void cleanup (void)
|
|||||||
|
|
||||||
free (runlevel);
|
free (runlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (applet);
|
|
||||||
applet = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int syslog_decode (char *name, CODE *codetab)
|
static int syslog_decode (char *name, CODE *codetab)
|
||||||
@ -815,10 +809,8 @@ int main (int argc, char **argv)
|
|||||||
bool parallel;
|
bool parallel;
|
||||||
int regen = 0;
|
int regen = 0;
|
||||||
|
|
||||||
|
applet = cbasename (argv[0]);
|
||||||
atexit (cleanup);
|
atexit (cleanup);
|
||||||
if (argv[0])
|
|
||||||
applet = xstrdup (basename (argv[0]));
|
|
||||||
|
|
||||||
if (! applet)
|
if (! applet)
|
||||||
eerrorx ("arguments required");
|
eerrorx ("arguments required");
|
||||||
|
|
||||||
|
2
src/rc.h
2
src/rc.h
@ -150,7 +150,7 @@ char **rc_service_extra_commands (const char *service);
|
|||||||
/*! Check if the service is allowed to be hot/cold plugged
|
/*! Check if the service is allowed to be hot/cold plugged
|
||||||
* @param service to check
|
* @param service to check
|
||||||
* @return true if allowed, otherwise false */
|
* @return true if allowed, otherwise false */
|
||||||
bool rc_service_plugable (char *service);
|
bool rc_service_plugable (const char *service);
|
||||||
|
|
||||||
/*! Resolves a service name to its full path.
|
/*! Resolves a service name to its full path.
|
||||||
* @param service to check
|
* @param service to check
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define APPLET "runscript"
|
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -40,7 +38,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -76,7 +73,7 @@
|
|||||||
|
|
||||||
#define ONE_SECOND 1000000000
|
#define ONE_SECOND 1000000000
|
||||||
|
|
||||||
static char *applet = NULL;
|
static const char *applet = NULL;
|
||||||
static char *service = NULL;
|
static char *service = NULL;
|
||||||
static char *exclusive = NULL;
|
static char *exclusive = NULL;
|
||||||
static char *mtime_test = NULL;
|
static char *mtime_test = NULL;
|
||||||
@ -353,7 +350,6 @@ static void cleanup (void)
|
|||||||
}
|
}
|
||||||
free (exclusive);
|
free (exclusive);
|
||||||
free (service);
|
free (service);
|
||||||
free (applet);
|
|
||||||
free (prefix);
|
free (prefix);
|
||||||
free (softlevel);
|
free (softlevel);
|
||||||
}
|
}
|
||||||
@ -502,7 +498,6 @@ static bool svc_exec (const char *arg1, const char *arg2)
|
|||||||
static bool svc_wait (rc_depinfo_t *depinfo, const char *svc)
|
static bool svc_wait (rc_depinfo_t *depinfo, const char *svc)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
char *base;
|
|
||||||
char *fifo;
|
char *fifo;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
int nloops = WAIT_MAX * (ONE_SECOND / WAIT_INTERVAL);
|
int nloops = WAIT_MAX * (ONE_SECOND / WAIT_INTERVAL);
|
||||||
@ -524,11 +519,7 @@ static bool svc_wait (rc_depinfo_t *depinfo, const char *svc)
|
|||||||
}
|
}
|
||||||
rc_strlist_free (keywords);
|
rc_strlist_free (keywords);
|
||||||
|
|
||||||
s = xstrdup (svc);
|
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", cbasename (svc), (char *) NULL);
|
||||||
base = basename (s);
|
|
||||||
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
|
|
||||||
free (s);
|
|
||||||
|
|
||||||
ts.tv_sec = 0;
|
ts.tv_sec = 0;
|
||||||
ts.tv_nsec = WAIT_INTERVAL;
|
ts.tv_nsec = WAIT_INTERVAL;
|
||||||
|
|
||||||
@ -1055,7 +1046,7 @@ int runscript (int argc, char **argv)
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
applet = xstrdup (basename (argv[1]));
|
applet = cbasename (argv[1]);
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
usage (EXIT_FAILURE);
|
usage (EXIT_FAILURE);
|
||||||
|
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define APPLET "start-stop-daemon"
|
|
||||||
|
|
||||||
/* nano seconds */
|
/* nano seconds */
|
||||||
#define POLL_INTERVAL 20000000
|
#define POLL_INTERVAL 20000000
|
||||||
#define WAIT_PIDFILE 500000000
|
#define WAIT_PIDFILE 500000000
|
||||||
@ -90,7 +88,7 @@ typedef struct schedulelist
|
|||||||
} schedulelist_t;
|
} schedulelist_t;
|
||||||
static schedulelist_t *schedule;
|
static schedulelist_t *schedule;
|
||||||
|
|
||||||
static char *applet;
|
static const char *applet;
|
||||||
static char *changeuser;
|
static char *changeuser;
|
||||||
static char **newenv;
|
static char **newenv;
|
||||||
|
|
||||||
@ -574,7 +572,7 @@ int start_stop_daemon (int argc, char **argv)
|
|||||||
char *svcname = getenv ("SVCNAME");
|
char *svcname = getenv ("SVCNAME");
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
applet = argv[0];
|
applet = cbasename (argv[0]);
|
||||||
atexit (cleanup);
|
atexit (cleanup);
|
||||||
|
|
||||||
signal (SIGINT, handle_signal);
|
signal (SIGINT, handle_signal);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user