aboutsummaryrefslogtreecommitdiff
path: root/src/util/os_priority.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-09 19:17:18 +0000
committerng0 <ng0@n0.is>2019-09-09 19:17:18 +0000
commit483b0139a218a5f8a8311bda3eb23bcd88f57688 (patch)
treed9e7a0f5053cdaa1a720485b93e9927f08466958 /src/util/os_priority.c
parentec472b1aae122481f4f7e760e5242753eba9bf87 (diff)
downloadgnunet-483b0139a218a5f8a8311bda3eb23bcd88f57688.tar.gz
gnunet-483b0139a218a5f8a8311bda3eb23bcd88f57688.zip
Remove win32 and cygwin support
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r--src/util/os_priority.c215
1 files changed, 3 insertions, 212 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index e4f2371e7..ebe469b3b 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -46,12 +46,6 @@ struct GNUNET_OS_Process {
46 */ 46 */
47 pid_t pid; 47 pid_t pid;
48 48
49#if WINDOWS
50 /**
51 * Process handle.
52 */
53 HANDLE handle;
54#endif
55 49
56 /** 50 /**
57 * Pipe we use to signal the process. 51 * Pipe we use to signal the process.
@@ -174,12 +168,7 @@ GNUNET_OS_install_parent_control_handler(void *cls)
174 putenv(GNUNET_OS_CONTROL_PIPE "="); 168 putenv(GNUNET_OS_CONTROL_PIPE "=");
175 return; 169 return;
176 } 170 }
177#if !defined(WINDOWS)
178 if (pipe_fd >= FD_SETSIZE) 171 if (pipe_fd >= FD_SETSIZE)
179#else
180 if ((FILE_TYPE_UNKNOWN == GetFileType((HANDLE)(uintptr_t)pipe_fd)) &&
181 (0 != GetLastError()))
182#endif
183 { 172 {
184 LOG(GNUNET_ERROR_TYPE_ERROR, 173 LOG(GNUNET_ERROR_TYPE_ERROR,
185 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", 174 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
@@ -187,12 +176,9 @@ GNUNET_OS_install_parent_control_handler(void *cls)
187 putenv(GNUNET_OS_CONTROL_PIPE "="); 176 putenv(GNUNET_OS_CONTROL_PIPE "=");
188 return; 177 return;
189 } 178 }
190#if WINDOWS 179
191 control_pipe =
192 GNUNET_DISK_get_handle_from_w32_handle((HANDLE)(uintptr_t)pipe_fd);
193#else
194 control_pipe = GNUNET_DISK_get_handle_from_int_fd((int)pipe_fd); 180 control_pipe = GNUNET_DISK_get_handle_from_int_fd((int)pipe_fd);
195#endif 181
196 if (NULL == control_pipe) 182 if (NULL == control_pipe)
197 { 183 {
198 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "open", env_buf); 184 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
@@ -222,12 +208,7 @@ GNUNET_OS_install_parent_control_handler(void *cls)
222struct GNUNET_OS_Process * 208struct GNUNET_OS_Process *
223GNUNET_OS_process_current() 209GNUNET_OS_process_current()
224{ 210{
225#if WINDOWS
226 current_process.pid = GetCurrentProcessId();
227 current_process.handle = GetCurrentProcess();
228#else
229 current_process.pid = 0; 211 current_process.pid = 0;
230#endif
231 return &current_process; 212 return &current_process;
232} 213}
233 214
@@ -259,72 +240,24 @@ GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
259 /* pipe failed or non-existent, try other methods */ 240 /* pipe failed or non-existent, try other methods */
260 switch (sig) 241 switch (sig)
261 { 242 {
262#if !defined(WINDOWS)
263 case SIGHUP: 243 case SIGHUP:
264#endif
265 case SIGINT: 244 case SIGINT:
266 case SIGKILL: 245 case SIGKILL:
267 case SIGTERM: 246 case SIGTERM:
268#if (SIGTERM != GNUNET_TERM_SIG) 247#if (SIGTERM != GNUNET_TERM_SIG)
269 case GNUNET_TERM_SIG: 248 case GNUNET_TERM_SIG:
270#endif 249#endif
271#if defined(WINDOWS) && !defined(__CYGWIN__)
272 {
273 DWORD exitcode;
274 int must_kill = GNUNET_YES;
275 if (0 != GetExitCodeProcess(proc->handle, &exitcode))
276 must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
277 if (GNUNET_YES == must_kill)
278 {
279 if (0 == SafeTerminateProcess(proc->handle, 0, 0))
280 {
281 DWORD error_code = GetLastError();
282 if ((error_code != WAIT_TIMEOUT) &&
283 (error_code != ERROR_PROCESS_ABORTED))
284 {
285 LOG((error_code == ERROR_ACCESS_DENIED) ? GNUNET_ERROR_TYPE_INFO
286 : GNUNET_ERROR_TYPE_WARNING,
287 "SafeTermiateProcess failed with code %lu\n",
288 error_code);
289 /* The problem here is that a process that is already dying
290 * might cause SafeTerminateProcess to fail with
291 * ERROR_ACCESS_DENIED, but the process WILL die eventually.
292 * If we really had a permissions problem, hanging up (which
293 * is what will happen in process_wait() in that case) is
294 * a valid option.
295 */
296 if (ERROR_ACCESS_DENIED == error_code)
297 {
298 errno = 0;
299 }
300 else
301 {
302 SetErrnoFromWinError(error_code);
303 return -1;
304 }
305 }
306 }
307 }
308 }
309 return 0;
310#else
311 LOG(GNUNET_ERROR_TYPE_DEBUG, 250 LOG(GNUNET_ERROR_TYPE_DEBUG,
312 "Sending signal %d to pid: %u via system call\n", 251 "Sending signal %d to pid: %u via system call\n",
313 sig, 252 sig,
314 proc->pid); 253 proc->pid);
315 return kill(proc->pid, sig); 254 return kill(proc->pid, sig);
316#endif
317 default: 255 default:
318#if defined(WINDOWS)
319 errno = EINVAL;
320 return -1;
321#else
322 LOG(GNUNET_ERROR_TYPE_DEBUG, 256 LOG(GNUNET_ERROR_TYPE_DEBUG,
323 "Sending signal %d to pid: %u via system call\n", 257 "Sending signal %d to pid: %u via system call\n",
324 sig, 258 sig,
325 proc->pid); 259 proc->pid);
326 return kill(proc->pid, sig); 260 return kill(proc->pid, sig);
327#endif
328 } 261 }
329} 262}
330 263
@@ -354,152 +287,11 @@ GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
354{ 287{
355 if (NULL != proc->control_pipe) 288 if (NULL != proc->control_pipe)
356 GNUNET_DISK_file_close(proc->control_pipe); 289 GNUNET_DISK_file_close(proc->control_pipe);
357#if defined(WINDOWS) 290
358 if (NULL != proc->handle)
359 CloseHandle(proc->handle);
360#endif
361 GNUNET_free(proc); 291 GNUNET_free(proc);
362} 292}
363 293
364 294
365#if WINDOWS
366#include "gnunet_signal_lib.h"
367
368extern GNUNET_SIGNAL_Handler w32_sigchld_handler;
369
370/**
371 * Make seaspider happy.
372 */
373#define DWORD_WINAPI DWORD WINAPI
374
375
376/**
377 * @brief Waits for a process to terminate and invokes the SIGCHLD handler
378 * @param proc pointer to process structure
379 */
380static DWORD_WINAPI
381child_wait_thread(void *arg)
382{
383 struct GNUNET_OS_Process *proc = (struct GNUNET_OS_Process *)arg;
384
385 WaitForSingleObject(proc->handle, INFINITE);
386
387 if (w32_sigchld_handler)
388 w32_sigchld_handler();
389
390 return 0;
391}
392#endif
393
394
395#if MINGW
396static char *
397CreateCustomEnvTable(char **vars)
398{
399 char *win32_env_table;
400 char *ptr;
401 char **var_ptr;
402 char *result;
403 char *result_ptr;
404 size_t tablesize = 0;
405 size_t items_count = 0;
406 size_t n_found = 0;
407 size_t n_var;
408 char *index = NULL;
409 size_t c;
410 size_t var_len;
411 char *var;
412 char *val;
413
414 win32_env_table = GetEnvironmentStringsA();
415 if (NULL == win32_env_table)
416 return NULL;
417 for (c = 0, var_ptr = vars; *var_ptr; var_ptr += 2, c++)
418 ;
419 n_var = c;
420 index = GNUNET_malloc(sizeof(char *) * n_var);
421 for (c = 0; c < n_var; c++)
422 index[c] = 0;
423 for (items_count = 0, ptr = win32_env_table; ptr[0] != 0; items_count++)
424 {
425 size_t len = strlen(ptr);
426 int found = 0;
427
428 for (var_ptr = vars; *var_ptr; var_ptr++)
429 {
430 var = *var_ptr++;
431 val = *var_ptr;
432 var_len = strlen(var);
433 if (strncmp(var, ptr, var_len) == 0)
434 {
435 found = 1;
436 index[c] = 1;
437 tablesize += var_len + strlen(val) + 1;
438 break;
439 }
440 }
441 if (!found)
442 tablesize += len + 1;
443 ptr += len + 1;
444 }
445 for (n_found = 0, c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
446 {
447 var = *var_ptr++;
448 val = *var_ptr;
449 if (index[c] != 1)
450 n_found += strlen(var) + strlen(val) + 1;
451 }
452 result = GNUNET_malloc(tablesize + n_found + 1);
453 for (result_ptr = result, ptr = win32_env_table; ptr[0] != 0;)
454 {
455 size_t len = strlen(ptr);
456 int found = 0;
457
458 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
459 {
460 var = *var_ptr++;
461 val = *var_ptr;
462 var_len = strlen(var);
463 if (strncmp(var, ptr, var_len) == 0)
464 {
465 found = 1;
466 break;
467 }
468 }
469 if (!found)
470 {
471 strcpy(result_ptr, ptr);
472 result_ptr += len + 1;
473 }
474 else
475 {
476 strcpy(result_ptr, var);
477 result_ptr += var_len;
478 strcpy(result_ptr, val);
479 result_ptr += strlen(val) + 1;
480 }
481 ptr += len + 1;
482 }
483 for (c = 0, var_ptr = vars; *var_ptr; var_ptr++, c++)
484 {
485 var = *var_ptr++;
486 val = *var_ptr;
487 var_len = strlen(var);
488 if (index[c] != 1)
489 {
490 strcpy(result_ptr, var);
491 result_ptr += var_len;
492 strcpy(result_ptr, val);
493 result_ptr += strlen(val) + 1;
494 }
495 }
496 FreeEnvironmentStrings(win32_env_table);
497 GNUNET_free(index);
498 *result_ptr = 0;
499 return result;
500}
501
502#else
503 295
504/** 296/**
505 * Open '/dev/null' and make the result the given 297 * Open '/dev/null' and make the result the given
@@ -529,7 +321,6 @@ open_dev_null(int target_fd, int flags)
529 } 321 }
530 GNUNET_break(0 == close(fd)); 322 GNUNET_break(0 == close(fd));
531} 323}
532#endif
533 324
534 325
535/** 326/**