Unable to add crontab entry in macOS Mojave

Hi All,

I find an issue with macOS Mojave that a program runnning using launch daemon is unable to add entry using 'crontab' with popen()/system() API's. I even tried to direclty modifying "/usr/lib/cron/tabs/$userFile" from program (just for testing) and even it fails.


In case I run the same program from terminal, it works. Also if we disable SIP (system integrity protection) then also it is sucessfully able to add crontab entry.


Even if this program is run through popen() from another launch deamon process still the issue occurs.


Is Anyone else also sees the issue and is there a solution/workaround for the same ?


Here is the sample program.



#include <iostream>

#include <stdio.h>

#include <pwd.h>

#include <unistd.h>

#include <fstream>

#include <sys/signal.h>


bool terminateFlag = false;


//Signal handler for SIGTERM

void terminationHandler(int signal)

{

terminateFlag = true;

}


bool writeCron(std::string fileName, int uid)

{

bool retVal = true;


do

{

std::string temp = "/usr/bin/crontab -u ";

temp.append(getpwuid(uid)->pw_name);

temp.append(" ");

temp.append(fileName);

FILE *f = popen(temp.c_str(),"r");

if(f == NULL)

{

retVal = false;

}

int retval = pclose(f);

if (retval != 0)

{

retVal = false;

printf("%s - failed with error %d", __FUNCTION__, retval);

}

} while (false);


return retVal;

}


// NOTE - contents of crontemp file is following => 21 22 22 7 * /usr/local/test1/test2/TaskManager 67 >> /dev/null 2>&1

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

signal(SIGINT, terminationHandler);


bool retVal = writeCron("./crontemp.txt", 0);


if (retVal)

{

exit(0);

}

else

{

while(!terminateFlag)

{

sleep(1);

}

}

return 0;

}

I can't make a launch daemon do anything at all under Mojave. I filed a bug report with this sample script as an attachment:


https://www.dropbox.com/s/5x45qgvq20cjncs/DaemonTest.zip?dl=1


But nothing's been fixed in the current beta.

Same here.. neither crontab nor launchdaemon will start anything that wasn't there before upgrade to Mojave.

I was getting the following error after Mojave upgrade while trying to add a crontab entry using "sudo crontab -e":

Operation not permitted


It turned out I needed to add my terminal app to the Settings.app "Security & Privacy" > "Full Disk Access" (I added both `terminal.app` and `iTerm.app`)

Something in Mojave must have tightened security ... which is good thing. After doing what @GabLeRoux stated, worked great ! Thanks GabLeRoux !

Unable to add crontab entry in macOS Mojave
 
 
Q