OSDN Git Service

init: Add 'readprops' command
authorAndrew Boie <andrew.p.boie@intel.com>
Fri, 12 Oct 2012 22:23:40 +0000 (15:23 -0700)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sun, 16 Jun 2013 06:52:01 +0000 (14:52 +0800)
This reads the contents of a text file and sets system properties
based on its contents.

Change-Id: Ic03de7ee9afb8a12439d0dff343560011e152beb
For: AXIA-102
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
init/builtins.c
init/init_parser.c
init/keywords.h
init/property_service.c
init/property_service.h
init/readme.txt

index 08374be..3138d0d 100644 (file)
@@ -984,3 +984,12 @@ int do_wait(int nargs, char **args)
     } else
         return -1;
 }
+
+int do_readprops(int nargs, char **args)
+{
+    if (nargs == 2) {
+        return load_properties_from_file(args[1]);
+    }
+    return -1;
+}
+
index a3d538e..4131fbd 100644 (file)
@@ -137,6 +137,7 @@ int lookup_keyword(const char *s)
         if (!strcmp(s, "robemod")) return K_probemod;
         break;
     case 'r':
+        if (!strcmp(s, "eadprops")) return K_readprops;
         if (!strcmp(s, "estart")) return K_restart;
         if (!strcmp(s, "estorecon")) return K_restorecon;
         if (!strcmp(s, "mdir")) return K_rmdir;
index 8ec36ec..86fd773 100644 (file)
@@ -38,6 +38,7 @@ int do_chmod(int nargs, char **args);
 int do_loglevel(int nargs, char **args);
 int do_load_persist_props(int nargs, char **args);
 int do_wait(int nargs, char **args);
+int do_readprops(int nargs, char **args);
 #define __MAKE_KEYWORD_ENUM__
 #define KEYWORD(symbol, flags, nargs, func) K_##symbol,
 enum {
@@ -69,6 +70,7 @@ enum {
     KEYWORD(oneshot,     OPTION,  0, 0)
     KEYWORD(onrestart,   OPTION,  0, 0)
     KEYWORD(probemod,    COMMAND, 1, do_probemod)
+    KEYWORD(readprops,   COMMAND, 1, do_readprops)
     KEYWORD(restart,     COMMAND, 1, do_restart)
     KEYWORD(restorecon,  COMMAND, 1, do_restorecon)
     KEYWORD(rm,          COMMAND, 1, do_rm)
index f58e07d..6815eaa 100755 (executable)
@@ -514,17 +514,20 @@ static void load_properties(char *data)
     }
 }
 
-static void load_properties_from_file(const char *fn)
+int load_properties_from_file(const char *fn)
 {
     char *data;
     unsigned sz;
 
     data = read_file(fn, &sz);
 
-    if(data != 0) {
-        load_properties(data);
-        free(data);
+    if(data == NULL) {
+        ERROR("Unable to read property file '%s'\n", fn);
+        return -1;
     }
+    load_properties(data);
+    free(data);
+    return 0;
 }
 
 static void load_persistent_properties()
index b9d1bf6..4b1b624 100644 (file)
@@ -22,6 +22,7 @@
 extern void handle_property_set_fd(void);
 extern void property_init(void);
 extern void property_load_boot_defaults(void);
+extern int load_properties_from_file(const char *fn);
 extern void load_persist_props(void);
 extern void start_property_service(void);
 void get_property_workspace(int *fd, int *sz);
index fe0d15d..ae43cfc 100644 (file)
@@ -182,6 +182,10 @@ mount <type> <device> <dir> [ <mountoption> ]*
    device by name.
    <mountoption>s include "ro", "rw", "remount", "noatime", ...
 
+readprops <path>
+   Read and set system properties based on the contents of a text file
+   at <path>
+
 setkey
    TBD