[Initng-svn] r1972 - in initng: . plugins/dparser plugins/ngc2
plugins/pidfile plugins/splash src tools
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon Nov 7 12:51:30 CET 2005
Author: jimmy
Date: Mon Nov 7 12:51:29 2005
New Revision: 1972
Modified:
initng/NEWS
initng/configure.in
initng/plugins/dparser/initng_d_parser.c
initng/plugins/ngc2/ngc2.c
initng/plugins/pidfile/initng_pidfile.c
initng/plugins/splash/initng_splash.c
initng/src/initng.h
initng/src/initng_handler.c
initng/src/initng_service_data_types.c
initng/src/initng_string_tools.c
initng/tools/install_service.c
Log:
Ready for initng-0.4.0
Also did an indention.
Modified: initng/NEWS
==============================================================================
--- initng/NEWS (original)
+++ initng/NEWS Mon Nov 7 12:51:29 2005
@@ -1,5 +1,30 @@
Version History:
---------------
+ 2005/11/07 13:00 (swedish timezone GMT+1)
+ initng-0.4.0 Try this one.
+ * New imanual.txt, tnx to Thomas Ilnseher
+ * ngc will only wait 10 seconds on staring/stoping services and not clutter the screen.
+ * Bug 197 finally fixed.
+ * Splashplugin update, will show icons with gensplash.
+ * grapth tool got an update, will work correctly.
+ * Fixed bug, that complied when we where stopping services, and it started stopping other by random.
+ * Only check for a pidfile, when daemon returns, and returns happily (return code 0)
+ * Added new option pid_of, will when daemon return search for a process with the name set here, and update daemon pid to that pid, be aware that you shud first try to run daemons in foreground, then use pidfile, this is a last solution.
+ * install_service.c Got some bugfixes and ability to search for daemons by using @syslogd@ in .ii files, this will simplyfy a lot in the future.
+ * main.c got some major cleanup.
+ * Made start_pause apply also for daemons.
+ * Only wait 120 seconds on segfault if initng is compiled with DEBUG set.
+ * Dont use new_environ() with sulogin, it can make initng hang, if it used before initng is inizialized global variables right.
+ * Made last pluing ignore TYPE_RUNLEVEL
+ * Bug 134, install killall5 and sysvinit replacement with the --enable-install-init
+ * splashy plugin got merged in splash plugin.
+ * Trigger did work on build system, every plugin can be disabled/enabled in ./configure
+ * ngc -L fixed, now shows all.
+ * Bugfix, dont segfault if /etc/initng/daemon or default dont exits.
+ * Lots of bugfixing.
+ * Lots of updates to .ii files.
+ * Lots of unpaid work by the initng team.
+
2005/11/02 22:00 (swedish timezone GMT+1)
initng-0.3.5 Getting closer to perfection.
* Added an runlevelEditor gui using python and pykde
Modified: initng/configure.in
==============================================================================
--- initng/configure.in (original)
+++ initng/configure.in Mon Nov 7 12:51:29 2005
@@ -1,7 +1,7 @@
dnl Written by Jimmy Wennlund <jimmy.wennlund at gmail.com>
AC_INIT(src/main.c)
-AM_INIT_AUTOMAKE(initng,0.3.5)
+AM_INIT_AUTOMAKE(initng,0.4.0)
AM_CONFIG_HEADER(config.h)
Modified: initng/plugins/dparser/initng_d_parser.c
==============================================================================
--- initng/plugins/dparser/initng_d_parser.c (original)
+++ initng/plugins/dparser/initng_d_parser.c Mon Nov 7 12:51:29 2005
@@ -27,7 +27,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <assert.h>
- /*#include <dirent.h> *//* opendir() closedir() */
+ /*#include <dirent.h> *//* opendir() closedir() */
#include "../../src/initng_string_tools.h"
#include "../../src/initng_service_cache.h"
Modified: initng/plugins/ngc2/ngc2.c
==============================================================================
--- initng/plugins/ngc2/ngc2.c (original)
+++ initng/plugins/ngc2/ngc2.c Mon Nov 7 12:51:29 2005
@@ -48,7 +48,8 @@
#define FALSE 0
int debug = 0;
-int header_printed=FALSE;
+int header_printed = FALSE;
+
/* Global comunication socket */
static int sock = -1;
@@ -178,22 +179,22 @@
/* read header data */
read(sock, result, sizeof(result_desc));
- if(header_printed==FALSE)
+ if (header_printed == FALSE)
{
- printf("Got an response from initng, version: %s\n", result->version);
+ printf("Got an response from initng, version: %s\n", result->version);
- if (strcmp(result->version, VERSION) != 0)
- {
- printf("Version of initng and version of ngc differs!\n");
- printf
- ("this might be a bad thing, that Can in worst case cause problems!\n");
- }
-
- /*printf("got an read: command %c, status %i, type %i\n", result->c,
- result->s, result->t); */
- header_printed=TRUE;
+ if (strcmp(result->version, VERSION) != 0)
+ {
+ printf("Version of initng and version of ngc differs!\n");
+ printf
+ ("this might be a bad thing, that Can in worst case cause problems!\n");
+ }
+
+ /*printf("got an read: command %c, status %i, type %i\n", result->c,
+ result->s, result->t); */
+ header_printed = TRUE;
}
-
+
if (result->s == FALSE)
{
printf("result of %c is false = %i!\n", result->c, result->s);
@@ -231,7 +232,7 @@
printf("Starting service: \n");
- while (counter<10)
+ while (counter < 10)
{
read(sock, &row, sizeof(active_row));
close_socket();
@@ -256,7 +257,7 @@
close_socket();
return (FALSE);
}
- counter++;
+ counter++;
}
close_socket();
@@ -267,10 +268,10 @@
return (TRUE);
}
- if(counter==10)
+ if (counter == 10)
{
- printf("Timeout on start service, might be started soon anyway.\n");
- return(FALSE);
+ printf("Timeout on start service, might be started soon anyway.\n");
+ return (FALSE);
}
@@ -284,7 +285,7 @@
{
active_row row;
result_desc *result = NULL;
- int counter=0;
+ int counter = 0;
printf("Stopping service: \n");
@@ -294,7 +295,7 @@
goto cant;
- while (counter<10)
+ while (counter < 10)
{
/* sleep awhile */
sleep(1);
@@ -319,7 +320,7 @@
if (strlen(row.n) < 2)
break;
- counter++;
+ counter++;
}
close_socket();
@@ -328,11 +329,11 @@
printf("\tService stopped sucessfully!\n");
return (TRUE);
}
-
- if(counter==10)
+
+ if (counter == 10)
{
- printf("Timeout on stop service, might be stopped soon anyway.\n");
- return(FALSE);
+ printf("Timeout on stop service, might be stopped soon anyway.\n");
+ return (FALSE);
}
cant:
@@ -405,7 +406,8 @@
{
int cc = 1;
result_desc *result = NULL;
- header_printed=FALSE;
+
+ header_printed = FALSE;
Argv = argv[0];
/* print banner */
Modified: initng/plugins/pidfile/initng_pidfile.c
==============================================================================
--- initng/plugins/pidfile/initng_pidfile.c (original)
+++ initng/plugins/pidfile/initng_pidfile.c Mon Nov 7 12:51:29 2005
@@ -39,6 +39,7 @@
/* The name of the process, initng shud probe */
s_entry PIDOF = { "pid_of", STRING, 6, DAEMON_OPT };
+
/* The filename/path of a pidfile that initng can fetch pid no */
s_entry PIDFILE = { "pid_file", STRING, 8, DAEMON_OPT };
@@ -54,59 +55,65 @@
struct dirent *d;
FILE *fp;
pid_t pid;
- #define BUFF_SIZE 256
+
+#define BUFF_SIZE 256
char buf[BUFF_SIZE + 1];
-
+
D_("Will check for: %s\n", name);
-
- dir=opendir("/proc");
- if(!dir) return(-1);
-
+
+ dir = opendir("/proc");
+ if (!dir)
+ return (-1);
+
/* Walk through the directory. */
while ((d = readdir(dir)) != NULL)
{
- char *s=NULL;
- int len = 0;
-
- /* See if this is a process */
- if ((pid = atoi(d->d_name)) == 0) continue;
-
- /* Open the status file. */
- snprintf(buf, BUFF_SIZE, "/proc/%s/stat", d->d_name);
+ char *s = NULL;
+ int len = 0;
- /* Read SID & statname from it. */
- if (!(fp = fopen(buf, "r")))
- continue;
-
- buf[0] = '\0';
- fgets(buf, BUFF_SIZE, fp);
-
- s = buf;
-
- /* skip to the first space */
- while (*s && *s != ' ')
- s++;
- if(*s=='\0') continue;
-
- /* skip the space */
- s++;
-
- /* skipp the '(' char */
- if(*s!='(') continue;
- s++;
-
- /* count the lenght */
- while(s[len] && s[len]!=')')
- len++;
-
- if(strncmp(s, name, len)==0) {
- D_("Found %s with pid %d\n", name, pid);
- return(pid);
- }
+ /* See if this is a process */
+ if ((pid = atoi(d->d_name)) == 0)
+ continue;
+
+ /* Open the status file. */
+ snprintf(buf, BUFF_SIZE, "/proc/%s/stat", d->d_name);
+
+ /* Read SID & statname from it. */
+ if (!(fp = fopen(buf, "r")))
+ continue;
+
+ buf[0] = '\0';
+ fgets(buf, BUFF_SIZE, fp);
+
+ s = buf;
+
+ /* skip to the first space */
+ while (*s && *s != ' ')
+ s++;
+ if (*s == '\0')
+ continue;
+
+ /* skip the space */
+ s++;
+
+ /* skipp the '(' char */
+ if (*s != '(')
+ continue;
+ s++;
+
+ /* count the lenght */
+ while (s[len] && s[len] != ')')
+ len++;
+
+ if (strncmp(s, name, len) == 0)
+ {
+ D_("Found %s with pid %d\n", name, pid);
+ return (pid);
+ }
}
-
+
D_("Did not find a process with name %s\n", name);
- return(-1);
+ return (-1);
}
@@ -115,7 +122,7 @@
* be set RUNNING if there must exist a pidfile, and
* pid entry has to be updated.
*/
-int check_if_done(active_h *s, e_a_status status)
+int check_if_done(active_h * s, e_a_status status)
{
assert(s);
assert(s->name);
@@ -126,16 +133,16 @@
if (status != RUNNING)
return (TRUE);
- if(active_db_is(&INTERNAL_GOT_PID, s))
- return(TRUE);
+ if (active_db_is(&INTERNAL_GOT_PID, s))
+ return (TRUE);
/* Make sure the service uses a pidfile */
if (active_db_is(&PIDFILE, s) || active_db_is(&PIDOF, s))
{
- /* the service have to die, and check_on_kill have to collect the pid first */
+ /* the service have to die, and check_on_kill have to collect the pid first */
return (FALSE);
}
- return(TRUE);
+ return (TRUE);
}
/*
@@ -185,18 +192,18 @@
pid_t pid;
char *pidof;
- pidof=active_db_get_string(&PIDOF, s);
- if(!pidof)
- return(-1);
-
-
- pidof=fix_variables(pidof, s);
- if(pidof)
- return(-1);
-
- pid=pid_of(pidof);
+ pidof = active_db_get_string(&PIDOF, s);
+ if (!pidof)
+ return (-1);
+
+
+ pidof = fix_variables(pidof, s);
+ if (pidof)
+ return (-1);
+
+ pid = pid_of(pidof);
free(pidof);
- return(pid);
+ return (pid);
}
/* this will get the pid of PIDFILE entry of service */
@@ -206,25 +213,25 @@
char *pidfile;
/* get the pidfile */
- pidfile=active_db_get_string(&PIDFILE, s);
-
+ pidfile = active_db_get_string(&PIDFILE, s);
+
/* check so that its found */
- if(!pidfile)
- return(-1);
-
+ if (!pidfile)
+ return (-1);
+
/* fix the variables in the string */
- pidfile=fix_variables(pidfile, s);
-
- /* check so we got the string*/
- if(!pidfile)
- return(-1);
+ pidfile = fix_variables(pidfile, s);
+
+ /* check so we got the string */
+ if (!pidfile)
+ return (-1);
/* get the pid from the file */
- pid=pid_from_file(pidfile);
+ pid = pid_from_file(pidfile);
free(pidfile);
-
+
/* return the pid */
- return(pid);
+ return (pid);
}
static int check_on_kill(active_h * s, process_h * p)
@@ -233,7 +240,8 @@
assert(s->name);
assert(p);
- pid_t pid=-1;
+ pid_t pid = -1;
+
S_;
/* make sure its the start process this is about */
@@ -244,35 +252,36 @@
if (s->a_status != STARTING)
return (FALSE);
- D_("will handle %s status %s\n", s->name, active_db_get_status_string(s->a_status));
+ D_("will handle %s status %s\n", s->name,
+ active_db_get_status_string(s->a_status));
/* if rcode indicate failure, dont check for pidfile */
- if(p->r_code > 0)
- return(FALSE);
-
+ if (p->r_code > 0)
+ return (FALSE);
+
/* check if string PIDOF or PIDFILE exits */
- if(active_db_is(&PIDOF, s))
+ if (active_db_is(&PIDOF, s))
{
- D_("getting pid by PIDOF!\n");
- /* get pid by process name */
- pid=get_pidof(s);
- D_("result : %d\n", pid);
+ D_("getting pid by PIDOF!\n");
+ /* get pid by process name */
+ pid = get_pidof(s);
+ D_("result : %d\n", pid);
}
-
+
if (active_db_is(&PIDFILE, s))
{
- D_("getting pid by PIDFILE!\n");
- pid=get_pidfile(s);
- D_("result : %d\n", pid);
+ D_("getting pid by PIDFILE!\n");
+ pid = get_pidfile(s);
+ D_("result : %d\n", pid);
}
-
- if(pid < 2)
+
+ if (pid < 2)
{
- return(FALSE);
+ return (FALSE);
}
-
+
/* set the new pid, to that we got from pidof or pidfile */
p->pid = pid;
-
+
/* this will alter check_if_done abowe */
active_db_set(&INTERNAL_GOT_PID, s);
mark_service(s, RUNNING);
Modified: initng/plugins/splash/initng_splash.c
==============================================================================
--- initng/plugins/splash/initng_splash.c (original)
+++ initng/plugins/splash/initng_splash.c Mon Nov 7 12:51:29 2005
@@ -165,47 +165,46 @@
if (splash_type == GENSPLASH)
{
char svc_name[100];
- const char* svc_status = NULL;
- int i;
+ const char *svc_status = NULL;
+ int i;
- i = 0;
- if (service->name)
+ i = 0;
+ if (service->name)
{
if (strncmp(service->name, "net/", 4) == 0)
{
strncpy(svc_name, service->name, 100);
svc_name[3] = '.';
- }
- else
+ }
+ else
{
while (service->name[i] && service->name[i] != '/')
i++;
if (service->name[i])
i++;
- strncpy (svc_name, service->name + i, 100);
+ strncpy(svc_name, service->name + i, 100);
}
- if (service->a_status == LOADING ||
+ if (service->a_status == LOADING ||
service->a_status == STARTING ||
- service->a_status == WAITING_FOR_START_DEP)
+ service->a_status == WAITING_FOR_START_DEP)
svc_status = "svc_start";
- if (service->a_status == FAIL_STARTING ||
+ if (service->a_status == FAIL_STARTING ||
service->a_status == START_DEP_FAILED)
svc_status = "svc_start_failed";
- if (service->a_status == RUNNING ||
- service->a_status == DONE)
+ if (service->a_status == RUNNING || service->a_status == DONE)
svc_status = "svc_started";
- if (service->a_status == STOP_DEP_FAILED ||
+ if (service->a_status == STOP_DEP_FAILED ||
service->a_status == FAIL_STOPPING)
svc_status = "svc_stop_failed";
- if (service->a_status == STOPPED)
+ if (service->a_status == STOPPED)
svc_status = "svc_stopped";
- if (service->a_status == STOPPING ||
+ if (service->a_status == STOPPING ||
service->a_status == WAITING_FOR_STOP_DEP)
svc_status = "svc_stop";
- if (svc_status)
+ if (svc_status)
fprintf(fd, "update_svc %s %s\n", svc_name, svc_status);
- }
+ }
/*
* repaint is an Expensive operation, but required
* for the text string that says 10%, etc...
Modified: initng/src/initng.h
==============================================================================
--- initng/src/initng.h (original)
+++ initng/src/initng.h Mon Nov 7 12:51:29 2005
@@ -30,7 +30,7 @@
#include "initng_error.h"
/* default version string to show */
-#define INITNG_VERSION VERSION " Closer to perfection. "
+#define INITNG_VERSION VERSION " Try this one. "
/* unset this in an pruduction environment */
Modified: initng/src/initng_handler.c
==============================================================================
--- initng/src/initng_handler.c (original)
+++ initng/src/initng_handler.c Mon Nov 7 12:51:29 2005
@@ -98,7 +98,7 @@
break;
case START_DEP_MET:
handle_START_DEP_MET(current);
- break;
+ break;
default:
break;
}
@@ -558,7 +558,7 @@
case FAIL_STOPPING:
continue;
default:
- D_("still waiting for %s\n", current->name);
+ D_("still waiting for %s\n", current->name);
return;
}
@@ -572,7 +572,7 @@
return;
}
-
+
/* ok, stopping deps are met */
D_("Try set STOP_DEP_MET!\n");
mark_service(service_to_stop, STOP_DEP_MET);
@@ -622,17 +622,17 @@
{
if (process->pt != T_DAEMON)
continue;
-
+
if (process->pid <= 0)
- {
+ {
mark_service(service_to_stop, STOPPED);
- return;
- }
+ return;
+ }
if (kill(process->pid, 0) && errno == ESRCH)
{
- mark_service(service_to_stop, STOPPED);
- return;
+ mark_service(service_to_stop, STOPPED);
+ return;
}
}
@@ -683,6 +683,7 @@
static void kill_daemon(active_h * service_to_stop)
{
process_h *process = NULL;
+
assert(service_to_stop);
/* look for a T_DAEMON process */
@@ -691,20 +692,20 @@
if (process->pt == T_DAEMON)
break;
}
-
+
/* check so we got one */
- if(process->pt != T_DAEMON)
+ if (process->pt != T_DAEMON)
{
- F_("This daemon does not have a daemon_process!\n");
+ F_("This daemon does not have a daemon_process!\n");
list_del(&process->list);
process_db_free(process);
- return;
+ return;
}
-
+
/* check so that pid is good */
if (process->pid <= 0)
{
- F_("Bad PID %d in database!\n", process->pid);
+ F_("Bad PID %d in database!\n", process->pid);
list_del(&process->list);
process_db_free(process);
return;
@@ -716,16 +717,16 @@
F_("Trying to kill a service (%s) with a pid (%d), but there exists no process with this pid!\n", service_to_stop->name, process->pid);
list_del(&process->list);
process_db_free(process);
- return;
+ return;
}
W_(" Sending the process %i of %s, the SIGTERM signal!\n",
- process->pid, service_to_stop->name);
+ process->pid, service_to_stop->name);
/* Uhm, this doesnt work : kill(-service_to_stop->start_process->pid, SIGTERM); */
kill(process->pid, SIGTERM);
- alarm(SECONDS_BEFORE_KILL + 1); /* the alarm will try to kill stopping services */
+ alarm(SECONDS_BEFORE_KILL + 1); /* the alarm will try to kill stopping services */
D_("Clock is set, killed process %i (%s), have %i seconds to quit before SIGKILL\n", process->pid, service_to_stop->name, SECONDS_BEFORE_KILL);
}
Modified: initng/src/initng_service_data_types.c
==============================================================================
--- initng/src/initng_service_data_types.c (original)
+++ initng/src/initng_service_data_types.c Mon Nov 7 12:51:29 2005
@@ -46,11 +46,11 @@
{
if (current == ent)
{
- if(ent->opt_name)
- F_("Option %s, alredy added!\n", ent->opt_name);
- else
- F_("Option, alredy added!\n");
-
+ if (ent->opt_name)
+ F_("Option %s, alredy added!\n", ent->opt_name);
+ else
+ F_("Option, alredy added!\n");
+
return;
}
if (current->opt_name && ent->opt_name
@@ -63,8 +63,8 @@
/* add the option to the option_db list */
list_add(&ent->list, &g.option_db.list);
#ifdef DEBUG
- if(ent->opt_name)
- D_(" \"%s\" added to option_db!\n", ent->opt_name);
+ if (ent->opt_name)
+ D_(" \"%s\" added to option_db!\n", ent->opt_name);
#endif
}
Modified: initng/src/initng_string_tools.c
==============================================================================
--- initng/src/initng_string_tools.c (original)
+++ initng/src/initng_string_tools.c Mon Nov 7 12:51:29 2005
@@ -121,9 +121,8 @@
/* skip beginning first spaces */
JUMP_SPACES(*string)
-
- /* this might be an "comp pare" */
- if ((*string)[0] == '"' && to_cmp[0] != '"')
+ /* this might be an "comp pare" */
+ if ((*string)[0] == '"' && to_cmp[0] != '"')
(*string)++;
/* ok, strcasecmp this */
@@ -150,39 +149,41 @@
/* skip beginning first spaces */
JUMP_SPACES(*string);
- if(!(*string)[0] || (*string)[0]=='\n')
- return(NULL);
+ if (!(*string)[0] || (*string)[0] == '\n')
+ return (NULL);
/* handle '"' chars */
- if((*string)[0]=='"')
+ if ((*string)[0] == '"')
{
- (*string)++;
- i=strcspn(*string, "\"");
- if(i<1) return(NULL);
- td=i_strndup(*string, i);
- (*string)+=i;
- if(*string[0]=='"')
- (*string)++;
- return(td);
+ (*string)++;
+ i = strcspn(*string, "\"");
+ if (i < 1)
+ return (NULL);
+ td = i_strndup(*string, i);
+ (*string) += i;
+ if (*string[0] == '"')
+ (*string)++;
+ return (td);
}
/* handle '{' '}' chars */
- if((*string)[0]=='{')
+ if ((*string)[0] == '{')
{
- (*string)++;
- i=strcspn(*string, "}");
- if(i<1) return(NULL);
- td=i_strndup(*string, i);
- (*string)+=i;
- if(*string[0]=='}')
- (*string)++;
- return(td);
+ (*string)++;
+ i = strcspn(*string, "}");
+ if (i < 1)
+ return (NULL);
+ td = i_strndup(*string, i);
+ (*string) += i;
+ if (*string[0] == '}')
+ (*string)++;
+ return (td);
}
/* or copy until space tab newline, ; or , */
- i=strcspn(*string, " \t\n;,");
- if(i<1)
- return(NULL);
+ i = strcspn(*string, " \t\n;,");
+ if (i < 1)
+ return (NULL);
/* copy string */
td = i_strndup(*string, i);
(*string) += i;
@@ -202,39 +203,41 @@
/* skip beginning first spaces */
JUMP_SPACES(*string);
- if(!(*string)[0] || (*string)[0]=='\n')
- return(NULL);
+ if (!(*string)[0] || (*string)[0] == '\n')
+ return (NULL);
/* handle '"' chars */
- if((*string)[0]=='"')
+ if ((*string)[0] == '"')
{
- (*string)++;
- i=strcspn(*string, "\"");
- if(i<1) return(NULL);
- td=i_strndup(*string, i);
- (*string)+=i;
- if(*string[0]=='"')
- (*string)++;
- return(td);
+ (*string)++;
+ i = strcspn(*string, "\"");
+ if (i < 1)
+ return (NULL);
+ td = i_strndup(*string, i);
+ (*string) += i;
+ if (*string[0] == '"')
+ (*string)++;
+ return (td);
}
/* handle '{' '}' chars */
- if((*string)[0]=='{')
+ if ((*string)[0] == '{')
{
- (*string)++;
- i=strcspn(*string, "}");
- if(i<1) return(NULL);
- td=i_strndup(*string, i);
- (*string)+=i;
- if(*string[0]=='}')
- (*string)++;
- return(td);
+ (*string)++;
+ i = strcspn(*string, "}");
+ if (i < 1)
+ return (NULL);
+ td = i_strndup(*string, i);
+ (*string) += i;
+ if (*string[0] == '}')
+ (*string)++;
+ return (td);
}
/* or copy until space tab newline, ; or , */
- i=strcspn(*string, "\n;");
- if(i<1)
- return(NULL);
+ i = strcspn(*string, "\n;");
+ if (i < 1)
+ return (NULL);
/* copy string */
td = i_strndup(*string, i);
(*string) += i;
Modified: initng/tools/install_service.c
==============================================================================
--- initng/tools/install_service.c (original)
+++ initng/tools/install_service.c Mon Nov 7 12:51:29 2005
@@ -40,16 +40,16 @@
/*the string "blah" must be the FIRST parameter, but his improves perf a little bit */
#define MATCH(PATTERN, LINE) (strncmp(PATTERN, skip_spaces(LINE), sizeof(PATTERN) - 1) == 0)
-#define LEN(STR) (sizeof(STR) - 1)
+#define LEN(STR) (sizeof(STR) - 1)
-static const char* path;
+static const char *path;
/* for the latter paths, a trailing '/' is required ! */
-static const char* additional_paths[] = {
-"/sbin/",
-"/usr/sbin/",
-"/usr/local/sbin/",
-NULL
+static const char *additional_paths[] = {
+ "/sbin/",
+ "/usr/sbin/",
+ "/usr/local/sbin/",
+ NULL
};
/* this program will parse all .i files in installation
@@ -62,12 +62,17 @@
D_("Trying, with file \"%s\" : ", filename);
if (stat(filename, &tmp) == 0 && S_ISREG(tmp.st_mode))
{
- if (executable){
- if (! (tmp.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH | S_ISUID | S_ISGID | S_ISVTX))) {
+ if (executable)
+ {
+ if (!
+ (tmp.
+ st_mode & (S_IXUSR | S_IXGRP | S_IXOTH | S_ISUID | S_ISGID |
+ S_ISVTX)))
+ {
D_("Found it, but not an executable\n");
- return (FALSE);
- }
- }
+ return (FALSE);
+ }
+ }
D_("Found it.\n");
return (TRUE);
}
@@ -100,102 +105,120 @@
/* This should find string like @mknod@ and return a pointer to it if found,
* otherwise return NULL */
-static const char* find_at_phrases (const char* in) {
- const char* first;
- const char* second;
- const char* tmp;
-
- if (! (first = strchr(in, '@')))
- return NULL; /* no '@' */
- while (1) {
- if (! (second = strchr(first + 1, '@')))
- return NULL; /* only one '@' */
+static const char *find_at_phrases(const char *in)
+{
+ const char *first;
+ const char *second;
+ const char *tmp;
+
+ if (!(first = strchr(in, '@')))
+ return NULL; /* no '@' */
+ while (1)
+ {
+ if (!(second = strchr(first + 1, '@')))
+ return NULL; /* only one '@' */
for (tmp = first + 1; tmp < second; tmp++)
- if (*tmp == ' ' || *tmp == '\t') {
+ if (*tmp == ' ' || *tmp == '\t')
+ {
/* whitespace in between: no match */
first = second;
- continue;
- }
+ continue;
+ }
return first;
}
}
-static void parse_phrase(FILE* stream, const char* phrase) {
+static void parse_phrase(FILE * stream, const char *phrase)
+{
#define FILENAME_LEN 1000
char filename[FILENAME_LEN];
- const char* tmp;
+ const char *tmp;
int i;
-
- if (! *phrase) {
+
+ if (!*phrase)
+ {
fputc('@', stream);
- return;
+ return;
}
-
+
if (!path)
return;
tmp = path;
- while (1) {
+ while (1)
+ {
i = 0;
while (*tmp != ':' && *tmp != '\0' && i < FILENAME_LEN - 1)
filename[i++] = *(tmp++);
- if (*tmp)
- tmp++; /* skip ':' */
- if (filename[i] != '/')
- filename[i++] = '/';
- filename[i] = '\0';
- strncat(filename, phrase, FILENAME_LEN - 1 - i);
- /* TODO: check if executable*/
- if (is_exec(filename)) {
- fputs(filename, stream);
- return;
- }
- if (! *tmp){
+ if (*tmp)
+ tmp++; /* skip ':' */
+ if (filename[i] != '/')
+ filename[i++] = '/';
+ filename[i] = '\0';
+ strncat(filename, phrase, FILENAME_LEN - 1 - i);
+ /* TODO: check if executable */
+ if (is_exec(filename))
+ {
+ fputs(filename, stream);
+ return;
+ }
+ if (!*tmp)
+ {
/* here we passed all paths in PATH */
i = 0;
- while (additional_paths[i]) {
+ while (additional_paths[i])
+ {
strncpy(filename, additional_paths[i], FILENAME_LEN - 1);
- strncat(filename, phrase, FILENAME_LEN - 1 - strlen(additional_paths[i]));
- if (is_exec(filename)) {
+ strncat(filename, phrase,
+ FILENAME_LEN - 1 - strlen(additional_paths[i]));
+ if (is_exec(filename))
+ {
fputs(filename, stream);
return;
- }
+ }
i++;
- }
- fprintf(stderr, "WARNING: No executable found for \"%s\"\n", phrase);
- /* exit(1) ??? */
- return;
- }
+ }
+ fprintf(stderr, "WARNING: No executable found for \"%s\"\n",
+ phrase);
+ /* exit(1) ??? */
+ return;
+ }
}
}
-static void print_it(FILE* stream, const char* buf){
- const char* tmp;
- const char* phrase;
+static void print_it(FILE * stream, const char *buf)
+{
+ const char *tmp;
+ const char *phrase;
int i = 0;
+
#define PHRASE_LEN 1000
char phrase_name[PHRASE_LEN];
- while (1) {
+
+ while (1)
+ {
phrase_name[0] = '\0';
- if (!(phrase = find_at_phrases(buf))) {
+ if (!(phrase = find_at_phrases(buf)))
+ {
fputs(buf, stream);
- return;
+ return;
}
/* write all chars up to the beginning '@' thingie to stream */
- for (tmp = buf; tmp < phrase; tmp++)
+ for (tmp = buf; tmp < phrase; tmp++)
fputc(*tmp, stream);
-
- /* copy Phrase to phrase_name */
- i = 0;
- for (tmp = phrase + 1; *tmp != '@' && i < PHRASE_LEN; tmp++){
- phrase_name[i++] = *tmp;
- }
- phrase_name[i] = '\0';
- /* pasrse Phrase */
- parse_phrase(stream, phrase_name);
- /* re-adjust output buffer */
- buf = tmp + 1;
+
+ /* copy Phrase to phrase_name */
+ i = 0;
+ for (tmp = phrase + 1; *tmp != '@' && i < PHRASE_LEN; tmp++)
+ {
+ phrase_name[i++] = *tmp;
+ }
+ phrase_name[i] = '\0';
+ /* pasrse Phrase */
+ parse_phrase(stream, phrase_name);
+ /* re-adjust output buffer */
+ buf = tmp + 1;
}
}
@@ -263,13 +286,15 @@
return NULL;
}
-static inline const char* skip_spaces(const char* in) {
+static inline const char *skip_spaces(const char *in)
+{
while (*in == ' ' || *in == '\t')
in++;
return in;
}
-static inline int empty_elsed(const char* in) {
+static inline int empty_elsed(const char *in)
+{
in = skip_spaces(in);
in += LEN("#elsed");
while (*in == ' ' || *in == '\t')
@@ -285,17 +310,21 @@
* ' ' or '\t'
* the character after "distro" meight either be ' ', '\t' or '\n'
*/
-static inline int match_distro(const char* in, const char* distro) {
- const char* tmp;
+static inline int match_distro(const char *in, const char *distro)
+{
+ const char *tmp;
int len = strlen(distro);
+
tmp = skip_spaces(in);
- while (1) {
+ while (1)
+ {
tmp = strstr(tmp, distro);
- if (! tmp)
+ if (!tmp)
return 0;
- if ((tmp[-1] != ' ' && tmp[-1] != '\t') || (tmp[len] != ' ' && tmp[len] != '\t' && tmp[len] != '\n'))
- tmp++; /* this will make strstr not find the same part again */
- else
+ if ((tmp[-1] != ' ' && tmp[-1] != '\t')
+ || (tmp[len] != ' ' && tmp[len] != '\t' && tmp[len] != '\n'))
+ tmp++; /* this will make strstr not find the same part again */
+ else
return 1;
}
}
@@ -303,16 +332,18 @@
int main(int argc, char **argv)
{
int i = 1;
-
- FILE* in;
- FILE* out = NULL;
-
- const char* distro = NULL;
- const char* infile = NULL;
- const char* outfile = NULL;
- const char* data;
+
+ FILE *in;
+ FILE *out = NULL;
+
+ const char *distro = NULL;
+ const char *infile = NULL;
+ const char *outfile = NULL;
+ const char *data;
+
#define LINE_LEN 1000
char line[LINE_LEN];
+
#define EXEC_BUFFER_LEN 100000
char exec_buffer[EXEC_BUFFER_LEN];
int exec_buffer_free = EXEC_BUFFER_LEN - 1;
@@ -324,7 +355,7 @@
int if_block_print_out = 0;
int distro_len = -1;
-
+
path = getenv("PATH");
/* check cmdline for set distribution */
while (argv[i])
@@ -363,16 +394,17 @@
}
distro_len = strlen(distro);
fprintf(stderr, "Distribution set: \"%s\"\n", distro);
-
+
/* open input for writing */
if (!infile)
{
fprintf(stderr, "You have to set input file with -i\n");
exit(1);
}
- if (!(in = fopen(infile, "r"))){
- fprintf(stderr, "could not open input file!\n");
- exit(1);
+ if (!(in = fopen(infile, "r")))
+ {
+ fprintf(stderr, "could not open input file!\n");
+ exit(1);
}
/* open output for writing */
@@ -381,126 +413,163 @@
if (strstr(infile, ".ii"))
{
outfile = strndup(infile, strlen(infile) - 1);
- } else {
+ }
+ else
+ {
fprintf(stderr, "out with -o not set, defaulting to stdout.\n");
out = stdout;
- }
+ }
}
- if (!out && !(out = fopen(outfile, "w"))){
- fprintf(stderr, "could not open output file!\n");
- exit(1);
+ if (!out && !(out = fopen(outfile, "w")))
+ {
+ fprintf(stderr, "could not open output file!\n");
+ exit(1);
}
/* main loop */
while (1)
{
fgets(line, LINE_LEN, in);
- if (feof(in))
+ if (feof(in))
break;
- if (! in_block && line[0] != '#') {
- print_it(out, line);
- continue; /* read next line */
- }
-
- /* either in_block != 0 or line started with '#' */
- if (! in_block) {
- if (MATCH("#exec", line)){
- D_("found #exec \n");
- exec_buffer[0] = '\0';
- exec_buffer_free = EXEC_BUFFER_LEN - 1;
+ if (!in_block && line[0] != '#')
+ {
+ print_it(out, line);
+ continue; /* read next line */
+ }
+
+ /* either in_block != 0 or line started with '#' */
+ if (!in_block)
+ {
+ if (MATCH("#exec", line))
+ {
+ D_("found #exec \n");
+ exec_buffer[0] = '\0';
+ exec_buffer_free = EXEC_BUFFER_LEN - 1;
in_block = EXEC_BLOCK;
- continue;
- } else if (MATCH("#ifd", line)) {
+ continue;
+ }
+ else if (MATCH("#ifd", line))
+ {
D_("found #ifd\n");
- in_block = IF_BLOCK;
- if_block_print_out = 0;
- if_block_processed = 0;
- if (match_distro(line, distro)) {
+ in_block = IF_BLOCK;
+ if_block_print_out = 0;
+ if_block_processed = 0;
+ if (match_distro(line, distro))
+ {
D_("actual distro %s matches line %s", distro, line);
- if_block_print_out = 1;
- if_block_processed = 1;
- }
- continue;
- } else {
+ if_block_print_out = 1;
+ if_block_processed = 1;
+ }
+ continue;
+ }
+ else
+ {
/* line started with a '#', but we are not in_block, and the line was neither
- * #ifd nor #exec. so it's a comment.
- */
- if (MATCH("#elsed", line) ||
- MATCH("#endd", line) ||
- MATCH("#endexec", line)){
- fprintf(stderr, "WARNING: found #elsed, #end or #endexec, but not in BLOCK!\n");
- /* exit here ??? */
- }
- /* this is a comment so print it */
- print_it(out, line);
- continue; /* read next line */
- }
- }
+ * #ifd nor #exec. so it's a comment.
+ */
+ if (MATCH("#elsed", line) ||
+ MATCH("#endd", line) || MATCH("#endexec", line))
+ {
+ fprintf(stderr,
+ "WARNING: found #elsed, #end or #endexec, but not in BLOCK!\n");
+ /* exit here ??? */
+ }
+ /* this is a comment so print it */
+ print_it(out, line);
+ continue; /* read next line */
+ }
+ }
/* ok, we are in a block */
- if (in_block == IF_BLOCK) {
- if (if_block_print_out){
- /*if the block should be printed up to now */
- if (MATCH("#endd", line) || MATCH("#elsed", line)) {
- /* elsed or endd, but this section should be printed => stop printing */
- if_block_print_out = 0;
- /* endd => in_block = 0; */
- if (MATCH("#endd", line)) {
+ if (in_block == IF_BLOCK)
+ {
+ if (if_block_print_out)
+ {
+ /*if the block should be printed up to now */
+ if (MATCH("#endd", line) || MATCH("#elsed", line))
+ {
+ /* elsed or endd, but this section should be printed => stop printing */
+ if_block_print_out = 0;
+ /* endd => in_block = 0; */
+ if (MATCH("#endd", line))
+ {
D_("found #endd\n");
in_block = 0;
- } else {
+ }
+ else
+ {
D_("found #elsed\n");
- }
- continue;
- } else {
+ }
+ continue;
+ }
+ else
+ {
/* in if block that should be printed => print it */
print_it(out, line);
- continue;
- }
-
- } else {
+ continue;
+ }
+
+ }
+ else
+ {
/* if block that should not be printed: check for elsed, endd */
- if (MATCH("#elsed", line)){
+ if (MATCH("#elsed", line))
+ {
D_("found #elsed\n");
- /* now we need to check if there is some distro specified */
- if (empty_elsed(line)) {
+ /* now we need to check if there is some distro specified */
+ if (empty_elsed(line))
+ {
/*no distro specified */
- if (!if_block_processed) {
- /* this if block has not yet been processed, so print this one */
- if_block_print_out = 1;
- }
- continue;
- } else { /* #elsed blahblah */
- if (match_distro(line, distro)) {
- if_block_print_out = 1;
- if_block_processed = 1;
- continue;
- }
- }
- } else if (MATCH("#endd", line)) {
+ if (!if_block_processed)
+ {
+ /* this if block has not yet been processed, so print this one */
+ if_block_print_out = 1;
+ }
+ continue;
+ }
+ else
+ { /* #elsed blahblah */
+ if (match_distro(line, distro))
+ {
+ if_block_print_out = 1;
+ if_block_processed = 1;
+ continue;
+ }
+ }
+ }
+ else if (MATCH("#endd", line))
+ {
D_("found #endd\n");
- in_block = 0;
- continue;
- } else
- continue;
- }
- } else {
+ in_block = 0;
+ continue;
+ }
+ else
+ continue;
+ }
+ }
+ else
+ {
/* in_block == EXEC_BLOCK */
- if (MATCH("#endexec", line)) {
+ if (MATCH("#endexec", line))
+ {
D_("found #endexec\n");
- /* Do the exec shit*/
- data = do_exec(exec_buffer, strlen(exec_buffer));
- if (data){
- print_it(out, data);
- free((void*)data);
- }
- in_block = 0;
- continue;
- } else {
+ /* Do the exec shit */
+ data = do_exec(exec_buffer, strlen(exec_buffer));
+ if (data)
+ {
+ print_it(out, data);
+ free((void *) data);
+ }
+ in_block = 0;
+ continue;
+ }
+ else
+ {
strncat(exec_buffer, line, exec_buffer_free);
- exec_buffer_free -= strlen(line);
- continue;
- }
- }
+ exec_buffer_free -= strlen(line);
+ continue;
+ }
+ }
}
fclose(in);
fclose(out);
More information about the Initng-svn
mailing list