1254219Scy#include "ipf.h" 2254219Scy#include "ipmon.h" 3254219Scy 4254219Scystatic void *execute_parse __P((char **)); 5254219Scystatic void execute_destroy __P((void *)); 6254219Scystatic int execute_send __P((void *, ipmon_msg_t *)); 7254219Scystatic void execute_print __P((void *)); 8254219Scy 9254219Scytypedef struct execute_opts_s { 10254219Scy char *path; 11254219Scy} execute_opts_t; 12254219Scy 13254219Scyipmon_saver_t executesaver = { 14254219Scy "execute", 15254219Scy execute_destroy, 16254219Scy NULL, /* dup */ 17254219Scy NULL, /* match */ 18254219Scy execute_parse, 19254219Scy execute_print, 20254219Scy execute_send 21254219Scy}; 22254219Scy 23254219Scy 24254219Scystatic void * 25254219Scyexecute_parse(char **strings) 26254219Scy{ 27254219Scy execute_opts_t *ctx; 28254219Scy 29254219Scy ctx = calloc(1, sizeof(*ctx)); 30254219Scy 31254219Scy if (ctx != NULL && strings[0] != NULL && strings[0][0] != '\0') { 32254219Scy ctx->path = strdup(strings[0]); 33254219Scy 34254219Scy } else { 35254219Scy free(ctx); 36254219Scy return NULL; 37254219Scy } 38254219Scy 39254219Scy return ctx; 40254219Scy} 41254219Scy 42254219Scy 43254219Scystatic void 44254219Scyexecute_print(ctx) 45254219Scy void *ctx; 46254219Scy{ 47254219Scy execute_opts_t *exe = ctx; 48254219Scy 49254219Scy printf("%s", exe->path); 50254219Scy} 51254219Scy 52254219Scy 53254219Scystatic void 54254219Scyexecute_destroy(ctx) 55254219Scy void *ctx; 56254219Scy{ 57254219Scy execute_opts_t *exe = ctx; 58254219Scy 59254219Scy if (exe != NULL) 60254219Scy free(exe->path); 61254219Scy free(exe); 62254219Scy} 63254219Scy 64254219Scy 65254219Scystatic int 66254219Scyexecute_send(ctx, msg) 67254219Scy void *ctx; 68254219Scy ipmon_msg_t *msg; 69254219Scy{ 70254219Scy execute_opts_t *exe = ctx; 71254219Scy FILE *fp; 72254219Scy 73254219Scy fp = popen(exe->path, "w"); 74254219Scy if (fp != NULL) { 75254219Scy fwrite(msg->imm_msg, msg->imm_msglen, 1, fp); 76254219Scy pclose(fp); 77254219Scy } 78254219Scy return 0; 79254219Scy} 80254219Scy 81