]> code.delx.au - pulseaudio/commitdiff
add option to disallow module loading after startup
authorLennart Poettering <lennart@poettering.net>
Fri, 3 Sep 2004 22:44:55 +0000 (22:44 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Sep 2004 22:44:55 +0000 (22:44 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@177 fefdeb5f-60dc-0310-8127-8f9354f1896f

doc/todo
polyp/cmdline.c
polyp/cmdline.h
polyp/core.c
polyp/core.h
polyp/cpulimit.c
polyp/main.c
polyp/module.c

index 0da2a2e0da0ae00b5dce4e6891440e77b9af42ca..bfc29fab083c6b33dbd45f6bd2e5f5f9082e01a0 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -17,7 +17,6 @@
 - add sample directory
 - paman: show scache and sample size
 - add timing parameter to write callback of stream in client API
-- add option for disabling module loading
 
 ** later ***
 - xmlrpc/http
index c07e7bdc590eb95d7a3a33bf92b79445b41e00c3..265e0ec88e90b486aae81abe2643af0d1db9a181 100644 (file)
@@ -72,6 +72,7 @@ void pa_cmdline_help(const char *argv0) {
            "  -C         Open a command line on the running TTY\n"
            "  -n         Don't load configuration file (%s)\n"
            "  -D         Daemonize after loading the modules\n"
+           "  -d         Disallow module loading after startup\n"
            "  -f         Dont quit when the startup fails\n"
            "  -v         Verbose startup\n"
            "  -h         Show this help\n"
@@ -88,13 +89,19 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
     assert(argc && argv);
 
     cmdline = pa_xmalloc(sizeof(struct pa_cmdline));
-    cmdline->daemonize = cmdline->help = cmdline->verbose = cmdline->high_priority = cmdline->stay_root = cmdline->version = 0;
+    cmdline->daemonize =
+        cmdline->help =
+        cmdline->verbose =
+        cmdline->high_priority =
+        cmdline->stay_root =
+        cmdline->version =
+        cmdline->disallow_module_loading = 0;
     cmdline->fail = 1;
 
     buf = pa_strbuf_new();
     assert(buf);
     
-    while ((c = getopt(argc, argv, "L:F:CDhfvrRVn")) != -1) {
+    while ((c = getopt(argc, argv, "L:F:CDhfvrRVnd")) != -1) {
         switch (c) {
             case 'L':
                 pa_strbuf_printf(buf, "load %s\n", optarg);
@@ -127,9 +134,11 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) {
                 cmdline->version = 1;
                 break;
             case 'n':
-                no_default_config_file =1;
+                no_default_config_file = 1;
+                break;
+            case 'd':
+                cmdline->disallow_module_loading = 1;
                 break;
-                
             default:
                 goto fail;
         }
index 6a7f4dd7dc8d587eae7ff52c78263930cb14665a..7330a7162000e052eae21f449baa213033246571 100644 (file)
@@ -24,7 +24,7 @@
 
 
 struct pa_cmdline {
-    int daemonize, help, fail, verbose, high_priority, stay_root, version;
+    int daemonize, help, fail, verbose, high_priority, stay_root, version, disallow_module_loading;
     char *cli_commands;
 };
 
index 908564c102f59130de477ddad503cd379a5f3221..da6ace6a3e844da61fa1bd73d793cd87ce5b2ea4 100644 (file)
@@ -69,6 +69,8 @@ struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
     c->subscriptions = NULL;
 
     c->memblock_stat = pa_memblock_stat_new();
+
+    c->disallow_module_loading = 0;
     
     pa_check_for_sigpipe();
     
index a297d4e0ad54d0e496baad12bd016dc8a63b0c6d..ffcd018bc2219ccdae1b26a49100f870aed7a7d2 100644 (file)
@@ -46,6 +46,8 @@ struct pa_core {
     struct pa_subscription *subscriptions;
 
     struct pa_memblock_stat *memblock_stat;
+
+    int disallow_module_loading;
 };
 
 struct pa_core* pa_core_new(struct pa_mainloop_api *m);
index 822e1f3320379815b148cd944059038781a99654..7d6fa8619b2982aac592528d12c20b21c5c2b472 100644 (file)
@@ -31,7 +31,7 @@
 #include "cpulimit.h"
 #include "util.h"
 
-/* Utilize this much CPU time at most */
+/* Utilize this much CPU time at maximum */
 #define CPUTIME_PERCENT 70
 
 #define CPUTIME_INTERVAL_SOFT (5)
@@ -77,12 +77,17 @@ static void signal_handler(int sig) {
 
     if (phase == PHASE_IDLE) {
         time_t now;
+
+#ifdef PRINT_CPU_LOAD
         char t[256];
+#endif
 
         time(&now);
 
+#ifdef PRINT_CPU_LOAD
         snprintf(t, sizeof(t), "Using %0.1f%% CPU\n", (double)CPUTIME_INTERVAL_SOFT/(now-last_time)*100);
         write_err(t);
+#endif
         
         if (CPUTIME_INTERVAL_SOFT >= ((now-last_time)*(double)CPUTIME_PERCENT/100)) {
             static const char c = 'X';
@@ -115,7 +120,6 @@ static void callback(struct pa_mainloop_api*m, struct pa_io_event*e, int fd, enu
 }
 
 int pa_cpu_limit_init(struct pa_mainloop_api *m) {
-    int r;
     struct sigaction sa;
     assert(m && !api && !io_event && the_pipe[0] == -1 && the_pipe[1] == -1);
     
@@ -141,8 +145,10 @@ int pa_cpu_limit_init(struct pa_mainloop_api *m) {
     sigemptyset(&sa.sa_mask);
     sa.sa_flags = SA_RESTART;
     
-    r = sigaction(SIGXCPU, &sa, &sigaction_prev);
-    assert(r >= 0);
+    if (sigaction(SIGXCPU, &sa, &sigaction_prev) < 0) {
+        pa_cpu_limit_done();
+        return -1;
+    }
 
     installed = 1;
 
index eba15c35b2b92a411725061b5efef59fa4e51c2b..1c09276e20af4d4e91887fbf48b67203fdfc0605 100644 (file)
@@ -211,6 +211,9 @@ int main(int argc, char *argv[]) {
         retval = 0;
         if (cmdline->daemonize)
             pa_loop_write(daemon_pipe[1], &retval, sizeof(retval));
+
+        c->disallow_module_loading = cmdline->disallow_module_loading;
+        
         fprintf(stderr, __FILE__": mainloop entry.\n");
         if (pa_mainloop_run(mainloop, &retval) < 0)
             retval = 1;
index eb8a8acd608878c9937de5865d889ca9d355982d..fc71495377b69d1146f3f28f856ca63bae34b498 100644 (file)
@@ -54,6 +54,9 @@ struct pa_module* pa_module_load(struct pa_core *c, const char *name, const char
     
     assert(c && name);
 
+    if (c->disallow_module_loading)
+        goto fail;
+
     m = pa_xmalloc(sizeof(struct pa_module));
 
     m->name = pa_xstrdup(name);