[Previous]
[Contents]
[Next]

qnx_setclock()

set the current time of a clock

Synopsis:

#include <time.h>
int qnx_setclock( pid_t proc_pid,
                  clockid_t clock_id,
                  struct timespec *tp );

Description:

The qnx_setclock() function sets the current time of the clock of type clock_id from the buffer pointed to by tp on the node identified by proc_pid. If proc_pid is zero, the current node is used.

To set the time on another node, proc_pid should be passed as a virtual circuit to the process manager on that node. For example,

/* Attach a vc to the process manager on node 4 */
proc_pid = qnx_vc_attach( 4, PROC_PID, 0, 0 );

The only supported clock type is CLOCK_REALTIME.

The tp parameter points to a structure containing the following:

time_t tv_sec
The number of seconds since 1970.
time_t tv_nsec
The number of nanoseconds in the current second. This value increases by some multiple of nanoseconds, based on the system timer's period.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EINVAL
The clock_type is invalid.
EPERM
You don't have sufficient privilege to change the time.
ESRCH
The pid is invalid.

Examples:

/*
 * This program synchronizes the system clock of the
 * node address(s) provided as arguments with the
 * system clock of the node it is running on.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/vc.h>
#include <sys/kernel.h>

void main( int argc, char **argv )
  {
    nid_t node;
    pid_t procpid;
    struct timespec gtime;
    int i;

    for( i = 1; i < argc; i++ ) {

      node = strtol( argv[i], NULL, 0 );
      if( ( procpid = qnx_vc_attach( node, PROC_PID, 0,
             _VC_AT_SHARE ) ) == -1 ) {
         perror( "qnx_vc_attach" );
         fprintf( stderr,
            "Can't attach to node %ld\n", node );
         continue;
      }
      if( qnx_getclock( PROC_PID, CLOCK_REALTIME, &gtime )
         == 0 ) {
         if( qnx_setclock( procpid, CLOCK_REALTIME, &gtime )
              == -1 ) {
           perror( "qnx_setclock" );
           fprintf( stderr,
             "Can't set time on node %ld\n", node );
         }
      } else {
        perror( "qnx_getclock" );
      }
      qnx_vc_detach( procpid );
    }
    exit( 0 );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, clock_gettime(), clock_setres(), clock_settime(), qnx_vc_attach()


[Previous]
[Contents]
[Next]