(2): Notifying cron of changes to crontab files

2007-12-25 9:37:00

Howdy,

With some help from Tim Pointing <Tim.Pointing@dciem.dnd.ca>, I cobbled up

the following code snippet to test notification of the cron daemon on Solaris.

Seems to work, but as you can see I've only tested the cron queue and add

action combination.

The code is clearly NOT ready for production and really only allowed me to

test this approach.

Jeff.

--- C code snippet to notify cron of changes in a crontab ---

  #include <string.h>

  #include <sys/types.h>

  #include <sys/stat.h>

  #include <unistd.h>

  struct cron_update {

        char cron_queue;

        char cron_action;

        char cron_username[15];

        char cron_filename[9];

  };

  #define CRON_AT_QUEUE 'a'

  #define CRON_BATCH_QUEUE 'b' /* ? */

  #define CRON_CRON_QUEUE 'c'

  #define CRON_ADD_ACTION 'a'

  #define CRON_REMOVE_ACTION 'r'

  main(int argc, char *argv[]) {

    char *username;

    struct cron_update upd;

    char *tmp;

    int fifo;

    username=argv[1];

    memset(&upd,0,sizeof(upd));

    upd.cron_queue = CRON_CRON_QUEUE;

    upd.cron_action = CRON_ADD_ACTION;

    memccpy(upd.cron_username,username,0,8);

    memccpy(upd.cron_filename,username,0,8);

    fifo = open("/etc/cron.d/FIFO", O_WRONLY|O_NDELAY);

    write(fifo,&upd,sizeof(upd));

    close(fifo);

  }

-----------------------------------------------------------------------------

Jeff Putsch | Internet: putsch@unitrode.com

Unitrode |

7 Continental Blvd. | Fax : (US) 603-429-8564

Merrimack, NH 03054 USA | Voice : (US) 603-429-8626 (daytime)

Comments

Got something to say?

You must be logged in to post a comment.