diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-15 09:04:21 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-15 09:04:21 +0000 |
commit | 4b5f756c88898e7c3449807d420358d3a2ee8c0c (patch) | |
tree | 6c49c06abf8e9a9fdff1f65f5de980900ac7b684 | |
parent | aa2a5133a3d41c378c8d219cc8878597c97094df (diff) | |
download | gnunet-4b5f756c88898e7c3449807d420358d3a2ee8c0c.tar.gz gnunet-4b5f756c88898e7c3449807d420358d3a2ee8c0c.zip |
some code cleanup
-rw-r--r-- | src/util/disk.c | 3 | ||||
-rw-r--r-- | src/util/os_priority.c | 107 |
2 files changed, 72 insertions, 38 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index e293ccda2..4d2ec8d81 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_crypto_lib.h" | 34 | #include "gnunet_crypto_lib.h" |
35 | #include "disk.h" | 35 | #include "disk.h" |
36 | 36 | ||
37 | #define DEBUG_NPIPE GNUNET_YES | 37 | #define DEBUG_NPIPE GNUNET_NO |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Block size for IO for copying files. | 40 | * Block size for IO for copying files. |
@@ -1991,6 +1991,7 @@ GNUNET_DISK_npipe_create (char **fn, | |||
1991 | #endif | 1991 | #endif |
1992 | } | 1992 | } |
1993 | 1993 | ||
1994 | |||
1994 | /** | 1995 | /** |
1995 | * Opens already existing named pipe/FIFO | 1996 | * Opens already existing named pipe/FIFO |
1996 | * | 1997 | * |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 2f1b96d02..0a08cf9ce 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -47,68 +47,99 @@ static struct GNUNET_OS_Process current_process; | |||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * This handler is called when there are control data to be read on the pipe | 49 | * This handler is called when there are control data to be read on the pipe |
50 | * | ||
51 | * @param cls the 'struct GNUNET_DISK_FileHandle' of the control pipe | ||
52 | * @param tc scheduler context | ||
50 | */ | 53 | */ |
51 | void | 54 | static void |
52 | GNUNET_OS_parent_control_handler (void *cls, | 55 | parent_control_handler (void *cls, |
53 | const struct | 56 | const struct |
54 | GNUNET_SCHEDULER_TaskContext * tc) | 57 | GNUNET_SCHEDULER_TaskContext * tc) |
55 | { | 58 | { |
56 | struct GNUNET_DISK_FileHandle *control_pipe = (struct GNUNET_DISK_FileHandle *) cls; | 59 | struct GNUNET_DISK_FileHandle *control_pipe = (struct GNUNET_DISK_FileHandle *) cls; |
57 | int sig; | 60 | int sig; |
58 | 61 | ||
59 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__, tc->reason); | 62 | #if DEBUG_OS |
60 | 63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
64 | "`%s' invoked because of %d\n", | ||
65 | __FUNCTION__, | ||
66 | tc->reason); | ||
67 | #endif | ||
61 | if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 68 | if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
62 | { | ||
63 | GNUNET_DISK_npipe_close (control_pipe); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) != sizeof (sig)) | ||
68 | { | 69 | { |
69 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); | ||
70 | GNUNET_DISK_npipe_close (control_pipe); | 70 | GNUNET_DISK_npipe_close (control_pipe); |
71 | } | 71 | } |
72 | else | 72 | else |
73 | { | 73 | { |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig); | 74 | if (GNUNET_DISK_file_read (control_pipe, |
75 | raise (sig); | 75 | &sig, |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Re-scheduling the parent control handler pipe\n"); | 76 | sizeof (sig)) != sizeof (sig)) |
77 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, GNUNET_OS_parent_control_handler, control_pipe); | 77 | { |
78 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
79 | "GNUNET_DISK_file_read"); | ||
80 | GNUNET_DISK_npipe_close (control_pipe); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | #if DEBUG_OS | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
86 | "Got control code %d from parent\n", sig); | ||
87 | #endif | ||
88 | raise (sig); | ||
89 | #if DEBUG_OS | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
91 | "Re-scheduling the parent control handler pipe\n"); | ||
92 | #endif | ||
93 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
94 | control_pipe, | ||
95 | &parent_control_handler, control_pipe); | ||
96 | } | ||
78 | } | 97 | } |
79 | } | ||
80 | } | 98 | } |
81 | 99 | ||
100 | |||
82 | /** | 101 | /** |
83 | * Connects this process to its parent via pipe | 102 | * Task that connects this process to its parent via pipe |
84 | */ | 103 | */ |
85 | void | 104 | void |
86 | GNUNET_OS_install_parent_control_handler (void *cls, | 105 | GNUNET_OS_install_parent_control_handler (void *cls, |
87 | const struct | 106 | const struct |
88 | GNUNET_SCHEDULER_TaskContext * tc) | 107 | GNUNET_SCHEDULER_TaskContext * tc) |
89 | { | 108 | { |
90 | char *env_buf; | 109 | const char *env_buf; |
91 | struct GNUNET_DISK_FileHandle *control_pipe = NULL; | 110 | struct GNUNET_DISK_FileHandle *control_pipe; |
92 | 111 | ||
93 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); | 112 | env_buf = getenv (GNUNET_OS_CONTROL_PIPE); |
94 | if (env_buf == NULL || strlen (env_buf) <= 0) | 113 | if ( (env_buf == NULL) || (strlen (env_buf) <= 0) ) |
95 | { | 114 | { |
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not installing a handler because %s=%s\n", GNUNET_OS_CONTROL_PIPE, env_buf); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
97 | return; | 116 | _("Not installing a handler because $%s=%s\n"), |
98 | } | 117 | GNUNET_OS_CONTROL_PIPE, |
99 | 118 | env_buf); | |
100 | control_pipe = GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ, | 119 | return; |
101 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 120 | } |
121 | control_pipe = GNUNET_DISK_npipe_open (env_buf, | ||
122 | GNUNET_DISK_OPEN_READ, | ||
123 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
102 | if (control_pipe == NULL) | 124 | if (control_pipe == NULL) |
103 | { | 125 | { |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to open the pipe `%s'\n", env_buf); | 126 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
105 | return; | 127 | "open", |
106 | } | 128 | env_buf); |
107 | 129 | return; | |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding parent control handler pipe `%s' to the scheduler\n", env_buf); | 130 | } |
109 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, GNUNET_OS_parent_control_handler, control_pipe); | 131 | #if DEBUG_OS |
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
133 | "Adding parent control handler pipe `%s' to the scheduler\n", | ||
134 | env_buf); | ||
135 | #endif | ||
136 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
137 | control_pipe, | ||
138 | &parent_control_handler, | ||
139 | control_pipe); | ||
110 | } | 140 | } |
111 | 141 | ||
142 | |||
112 | /** | 143 | /** |
113 | * Get process structure for current process | 144 | * Get process structure for current process |
114 | * | 145 | * |
@@ -129,6 +160,7 @@ GNUNET_OS_process_current () | |||
129 | return ¤t_process; | 160 | return ¤t_process; |
130 | } | 161 | } |
131 | 162 | ||
163 | |||
132 | int | 164 | int |
133 | GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) | 165 | GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) |
134 | { | 166 | { |
@@ -227,6 +259,7 @@ GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc) | |||
227 | return proc->pid; | 259 | return proc->pid; |
228 | } | 260 | } |
229 | 261 | ||
262 | |||
230 | void | 263 | void |
231 | GNUNET_OS_process_close (struct GNUNET_OS_Process *proc) | 264 | GNUNET_OS_process_close (struct GNUNET_OS_Process *proc) |
232 | { | 265 | { |