source: trunk/Cocoa/Pester/Source/wakein.m @ 117

Last change on this file since 117 was 117, checked in by Nicholas Riley, 17 years ago

wakein.[hm]: pre-MoreSecurity? implementation

File size: 981 bytes
Line 
1//
2//  wakein.m
3//  Pester
4//
5//  Created by Nicholas Riley on Tue Mar 11 2003.
6//  Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import <Cocoa/Cocoa.h>
10#import "wakein.h"
11#import "unistd.h"
12#import "PSPowerManager.h"
13
14void usage() {
15    fprintf(stderr, "usage: wakein secs\n");
16    exit(PSWakeErrorSyntax);
17}
18
19int main(int argc, const char *argv[])
20{
21    [[NSAutoreleasePool alloc] init];
22
23    if (argc != 2) usage();
24
25    long long secs;
26    if (![[NSScanner scannerWithString: [NSString stringWithUTF8String: argv[1]]] scanLongLong: &secs])
27        usage();
28
29    if (secs < 0 || secs > ULONG_MAX)
30        usage();
31
32    if (geteuid() != 0) {
33        fprintf(stderr, "wakein: must be root\n");
34        return PSWakeErrorPermissions;
35    }
36
37    NS_DURING
38        [PSPowerManager setWakeInterval: secs];
39    NS_HANDLER
40        fprintf(stderr, "%s\n", [[localException description] UTF8String]);
41        return PSWakeErrorException;
42    NS_ENDHANDLER
43
44    return 0;
45}
Note: See TracBrowser for help on using the repository browser.