[Initng-svn] r1956 - initng/tools
svn at initng.thinktux.net
svn at initng.thinktux.net
Sun Nov 6 18:39:11 CET 2005
Author: SaTaN0r1
Date: Sun Nov 6 18:39:10 2005
New Revision: 1956
Modified:
initng/tools/install_service.c
Log:
now install_service.c will also look in /usr/sbin /sbin and /usr/local/sbin in addition to the path. This should ease it to build initng as ordinary user. it also checks if the files are executable.
Modified: initng/tools/install_service.c
==============================================================================
--- initng/tools/install_service.c (original)
+++ initng/tools/install_service.c Sun Nov 6 18:39:10 2005
@@ -42,18 +42,32 @@
#define MATCH(PATTERN, LINE) (strncmp(PATTERN, skip_spaces(LINE), sizeof(PATTERN) - 1) == 0)
#define LEN(STR) (sizeof(STR) - 1)
-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
+};
/* this program will parse all .i files in installation
setting distribution dependent values on install time */
-static int is_file(const char *filename)
+static int _is_file(const char *filename, int executable)
{
struct stat tmp;
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))) {
+ D_("Found it, but not an executable\n");
+ return (FALSE);
+ }
+ }
D_("Found it.\n");
return (TRUE);
}
@@ -61,6 +75,9 @@
return (FALSE);
}
+#define is_file(FILENAME) _is_file(FILENAME, 0)
+#define is_exec(FILENAME) _is_file(FILENAME, 1)
+
static const char *probe_distribution(void)
{
D_("probe_distribution\n");
@@ -129,12 +146,24 @@
filename[i] = '\0';
strncat(filename, phrase, FILENAME_LEN - 1 - i);
/* TODO: check if executable*/
- if (is_file(filename)) {
+ if (is_exec(filename)) {
fputs(filename, stream);
return;
}
if (! *tmp){
+ /* here we passed all paths in PATH */
+ i = 0;
+ 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)) {
+ fputs(filename, stream);
+ return;
+ }
+ i++;
+ }
fprintf(stderr, "WARNING: No executable found for \"%s\"\n", phrase);
+ /* exit(1) ??? */
return;
}
}
More information about the Initng-svn
mailing list