Skip to content

Commit 83eded8

Browse files
committed
Graceful exit when program path doesn't exist
Fixes #1522
1 parent f3945bd commit 83eded8

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/bindings/c/bindings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ void processoptions_freeString(char *string);
270270
// Will return a NULL pointer if the path does not exist.
271271
char *processoptions_getPath(const struct ProcessOptions *proc);
272272

273+
// Returns the path exactly as specified in the config. Caller must free returned string.
274+
char *processoptions_getRawPath(const struct ProcessOptions *proc);
275+
273276
void processoptions_getArgs(const struct ProcessOptions *proc,
274277
void (*f)(const char*, void*),
275278
void *data);

src/main/core/controller.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ static void _controller_registerProcessCallback(const ProcessOptions* proc, void
229229

230230
char* plugin = processoptions_getPath(proc);
231231
if (plugin == NULL) {
232-
utility_panic("The process binary could not be found");
232+
error("For host '%s', couldn't find program path: '%s'", callbackArgs->hostname,
233+
processoptions_getRawPath(proc));
234+
exit(EXIT_FAILURE);
233235
}
234236

235237
// build an argv array

src/main/core/support/configuration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,14 @@ mod export {
15771577
}
15781578
}
15791579

1580+
/// Returns the path exactly as specified in the config. Caller must free returned string.
1581+
#[no_mangle]
1582+
pub extern "C" fn processoptions_getRawPath(proc: *const ProcessOptions) -> *mut libc::c_char {
1583+
assert!(!proc.is_null());
1584+
let proc = unsafe { proc.as_ref().unwrap() };
1585+
CString::into_raw(CString::new(proc.path.to_string_lossy().as_bytes()).unwrap())
1586+
}
1587+
15801588
#[no_mangle]
15811589
pub extern "C" fn processoptions_getArgs(
15821590
proc: *const ProcessOptions,

0 commit comments

Comments
 (0)