Thursday, August 26, 2010

What's the proper way to safely run this error-prone system call in perl?

Programmer Question

So as part of a startup script for OS X computer lab systems, I am running a built-in shell command called systemsetup to sync the system with a network time server. It's running inside a perl script as follows.



#!/usr/bin/perl

system("systemsetup -setusingnetworktime off");
system("systemsetup -setusingnetworktime on");


Flipping it to off first ensures that it updates when it is flipped on.



The problem is that every so often, that command throws the following error writeconfig[1841:903] *** -[NSMachPort handlePortMessage:]: dropping incoming DO message because the connection or ports are invalid and then stalls either the shell or the script's execution depending on where I'm running it.



This actually happens shockingly little in practice—on 500 lab systems running the script daily at boot, I only notice a problem on a single system every few weeks. Strangely, it's actually very easy to replicate in testing.



So what I understand is that this is fairly obviously a bug in systemsetup that that error is being thrown, but I'm sure there's a way to make my perl script handle it gracefully, right?



The best thing I've come up with at the moment is systemsetup -setusingnetworktime off&>/dev/null which pipes both STDOUT and STDERR to /dev/null.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails