Skip to content

Commit

Permalink
popen_wdt: Use different type for win/posix exitcode
Browse files Browse the repository at this point in the history
- And change POPEN_WDT_EXIT_INITIALIZER with POPEN_WDT_EXIT_CODE_MAX
  • Loading branch information
Royna2544 committed Dec 4, 2024
1 parent 35ed926 commit b753687
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/command_modules/support/popen_wdt/popen_wdt.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "popen_wdt.h"
#include <stdlib.h>
#include <string.h>

bool popen_watchdog_init(popen_watchdog_data_t **data) {
if (data != NULL) {
*data = calloc(1, sizeof(popen_watchdog_data_t));
if (*data != NULL) {
(*data)->sleep_secs = 10;
(*data)->sleep_secs = POPEN_WDT_DEFAULT_SLEEP_SECS;
return true;
}
}
Expand Down
22 changes: 18 additions & 4 deletions src/command_modules/support/popen_wdt/popen_wdt.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#pragma once

#include <stdbool.h>
#include <stdint.h>
#include <limits.h>
#ifdef _WIN32
#include <windows.h>
#endif

#ifndef NDEBUG
#define POPEN_WDT_DEBUG
#endif

#ifdef _WIN32
typedef DWORD popen_watchdog_exit_code_t;
#define POPEN_WDT_EXIT_CODE_MAX ULONG_MAX
#else
typedef uint8_t popen_watchdog_exit_code_t;
#define POPEN_WDT_EXIT_CODE_MAX UINT8_MAX
#endif

#define POPEN_WDT_DEFAULT_SLEEP_SECS 10

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -14,12 +29,11 @@ extern "C" {
#define POPEN_WDT_SIGTERM 2

typedef struct {
int exitcode; /* exit code of the process, default -255 */
bool signal; /* if the process was signaled, then the exit code becomes the
signum */
popen_watchdog_exit_code_t exitcode; /* exit code of the process, default POPEN_WDT_EXIT_CODE_MAX */
bool signal; /* if the process was signaled, if yes, exitcode is signal num */
} popen_watchdog_exit_t;

#define POPEN_WDT_EXIT_INITIALIZER { -1, false }
#define POPEN_WDT_EXIT_INITIALIZER { POPEN_WDT_EXIT_CODE_MAX, false }

typedef struct {
const char *command; /* command string */
Expand Down

0 comments on commit b753687

Please sign in to comment.