~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Tools/gdnc.m

Tags: upstream-1.11.2
ImportĀ upstreamĀ versionĀ 1.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   You should have received a copy of the GNU General Public
15
15
   License along with this library; see the file COPYING.LIB.
16
16
   If not, write to the Free Software Foundation,
17
 
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
 
19
19
   */
20
20
 
24
24
#include        <stdio.h>
25
25
#include        <unistd.h>
26
26
 
27
 
#ifdef __MINGW__
 
27
#if     defined(__MINGW32__)
28
28
#include        "process.h"
29
29
#endif
30
30
 
104
104
{
105
105
  static BOOL   beenHere = NO;
106
106
  BOOL          action;
107
 
  const char    *e;
 
107
  NSString      *e;
108
108
 
109
109
  /*
110
110
   * Deal with recursive call of handler.
128
128
#else
129
129
  action = NO;          // exit() by default.
130
130
#endif
131
 
  e = getenv("CRASH_ON_ABORT");
132
 
  if (e != 0)
 
131
  e = [[[NSProcessInfo processInfo] environment] objectForKey:
 
132
    @"CRASH_ON_ABORT"];
 
133
  if (e != nil)
133
134
    {
134
 
      if (strcasecmp(e, "yes") == 0 || strcasecmp(e, "true") == 0)
135
 
        action = YES;
136
 
      else if (strcasecmp(e, "no") == 0 || strcasecmp(e, "false") == 0)
137
 
        action = NO;
138
 
      else if (isdigit(*e) && *e != '0')
139
 
        action = YES;
140
 
      else
141
 
        action = NO;
 
135
      action = [e boolValue];
142
136
    }
143
137
 
144
138
  if (action == YES)
174
168
                            selector: (NSString*)aSelector
175
169
                                  to: (unsigned long)observer
176
170
{
 
171
  return;
177
172
}
178
173
@end
179
174
 
363
358
 
364
359
- (id) init
365
360
{
366
 
  NSString      *hostname;
367
 
  NSString      *service = GDNC_SERVICE;
368
 
  BOOL          isLocal = NO;
 
361
  NSString              *hostname;
 
362
  NSString              *service;
 
363
  BOOL                  isNetwork = NO;
 
364
  BOOL                  isPublic = NO;
 
365
  BOOL                  isLocal = NO;
 
366
  NSPort                *port;
 
367
  NSPortNameServer      *ns;
 
368
  NSUserDefaults        *defs;
369
369
 
370
370
  connections = NSCreateMapTable(NSObjectMapKeyCallBacks,
371
371
                NSNonOwnedPointerMapValueCallBacks, 0);
373
373
  observersForNames = [NSMutableDictionary new];
374
374
  observersForObjects = [NSMutableDictionary new];
375
375
 
376
 
  if ([[NSUserDefaults standardUserDefaults] boolForKey: @"GSNetwork"] == YES)
 
376
  defs = [NSUserDefaults standardUserDefaults];
 
377
  hostname = [defs stringForKey: @"NSHost"];
 
378
  if ([hostname length] > 0 || [defs boolForKey: @"GSPublic"] == YES)
 
379
    {
 
380
      if (hostname == nil || [hostname isEqualToString: @"localhost"] == YES
 
381
        || [hostname isEqualToString: @"127.0.0.1"] == YES)
 
382
        {
 
383
          hostname = @"";
 
384
        }
 
385
      isPublic = YES;
 
386
    }
 
387
  else if ([defs boolForKey: @"GSNetwork"] == YES)
 
388
    {
 
389
      isNetwork = YES;
 
390
    }
 
391
  else
 
392
    {
 
393
      isLocal = YES;
 
394
    }
 
395
 
 
396
 
 
397
  if (isNetwork)
377
398
    {
378
399
      service = GDNC_NETWORK;
379
 
    }
380
 
  hostname = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
 
400
      ns = [NSSocketPortNameServer sharedInstance];
 
401
      port = (NSPort*)[NSSocketPort port];
 
402
    }
 
403
  else if (isPublic)
 
404
    {
 
405
      service = GDNC_SERVICE;
 
406
      ns = [NSSocketPortNameServer sharedInstance];
 
407
      if (isLocal == YES)
 
408
        {
 
409
          port = (NSPort*)[NSSocketPort portWithNumber: 0
 
410
                                                onHost: [NSHost localHost]
 
411
                                          forceAddress: @"127.0.0.1"
 
412
                                              listener: YES];
 
413
        }
 
414
      else
 
415
        {
 
416
          port = (NSPort*)[NSSocketPort port];
 
417
        }
 
418
    }
 
419
  else
 
420
    {
 
421
      NSUserDefaults    *defs = [NSUserDefaults standardUserDefaults];
 
422
 
 
423
      if ([defs objectForKey: @"NSPortIsMessagePort"] != nil
 
424
        && [defs boolForKey: @"NSPortIsMessagePort"] == NO)
 
425
        {
 
426
          ns = [NSSocketPortNameServer sharedInstance];
 
427
          port = (NSPort*)[NSSocketPort port];
 
428
        }
 
429
      else
 
430
        {
 
431
          ns = [NSMessagePortNameServer sharedInstance];
 
432
          port = (NSPort*)[NSMessagePort port];
 
433
        }
 
434
      hostname = @"";
 
435
      service = GDNC_SERVICE;
 
436
    }
 
437
 
 
438
  conn = [[NSConnection alloc] initWithReceivePort: port sendPort: nil];
 
439
  [conn setRootObject: self];
 
440
 
381
441
  if ([hostname length] == 0
382
 
    || [hostname isEqualToString: @"localhost"] == YES
383
 
    || [hostname isEqualToString: @"127.0.0.1"] == YES)
384
 
    {
385
 
      isLocal = YES;
386
 
    }
387
 
 
388
 
  /*
389
 
   * If this is the local server for the current host,
390
 
   * use the loopback network interface.  Otherwise
391
 
   * create a public connection.
392
 
   */
393
 
  if (0 && isLocal == YES && service != GDNC_NETWORK)
394
 
    {
395
 
      /* If this code is reactivated, it needs to deal correctly with the
396
 
      case where NSSocketPort shouldn't be used (because it isn't the
397
 
      default port). Something like
398
 
        NSPort *port = [NSMessagePort port];
399
 
      or just
400
 
        NSPort *port = [NSPort port];
401
 
      */
402
 
      NSPort    *port = [NSSocketPort portWithNumber: 0
403
 
                                              onHost: [NSHost localHost]
404
 
                                        forceAddress: @"127.0.0.1"
405
 
                                            listener: YES];
406
 
      conn = [[NSConnection alloc] initWithReceivePort: port sendPort: nil];
407
 
    }
408
 
  else
409
 
    {
410
 
      conn = [NSConnection defaultConnection];
411
 
    }
412
 
  [conn setRootObject: self];
413
 
 
414
 
  if (isLocal == YES
415
442
    || [[NSHost hostWithName: hostname] isEqual: [NSHost currentHost]] == YES)
416
443
    {
417
 
      if ([conn registerName: service] == NO)
 
444
      if ([conn registerName: service withNameServer: ns] == NO)
418
445
        {
419
446
          NSLog(@"gdnc - unable to register with name server as %@ - quiting.",
420
447
            service);
426
453
    {
427
454
      NSHost            *host = [NSHost hostWithName: hostname];
428
455
      NSPort            *port = [conn receivePort];
429
 
      NSPortNameServer  *ns = [NSPortNameServer systemDefaultPortNameServer];
430
456
      NSArray           *a;
431
457
      unsigned          c;
432
458
 
978
1004
@end
979
1005
 
980
1006
 
981
 
/** <p>The  gdnc  daemon is used by GNUstep programs to send notifications and
982
 
       messages to one another, in conjunction with the Base library
983
 
       Notification-related classes.</p>
984
 
 
985
 
    <p>Every user needs to have his own instance of gdnc running.  While  gdnc
986
 
       will be started automatically as soon as it is needed, it is recommended
987
 
       to start gdnc in a personal login script like  ~/.bashrc  or  ~/.cshrc.
988
 
       Alternatively  you  can  launch  gpbs when your windowing system or the
989
 
       window manager is started. For example, on systems  with  X11  you  can
990
 
       launch  gdnc  from  your  .xinitrc script or alternatively - if you are
991
 
       running Window Maker - put it in Window Maker's autostart script.   See
992
 
       the GNUstep Build Guide for a sample startup script.</p>
993
 
 
994
 
     <p>Please see the man page for more information.
995
 
</p> */
 
1007
/**
 
1008
  <p>The  gdnc  daemon is used by GNUstep programs to send notifications and
 
1009
     messages to one another, in conjunction with the Base library
 
1010
     Notification-related classes.</p>
 
1011
 
 
1012
  <p>Every user needs to have his own instance of gdnc running.  While  gdnc
 
1013
     will be started automatically as soon as it is needed, it is recommended
 
1014
     to start gdnc in a personal login script like  ~/.bashrc  or  ~/.cshrc.
 
1015
     Alternatively (if you have no command-line tools which use distributed
 
1016
     notifications) you  can  launch gdnc when your windowing system or the
 
1017
     window manager is started. For example, on systems  with  X11  you  can
 
1018
     launch  gdnc  from  your  .xinitrc script or alternatively - if you are
 
1019
     running Window Maker - put it in Window Maker's autostart script.   See
 
1020
     the GNUstep Build Guide for a sample startup script.</p>
 
1021
 
 
1022
  <p>Please see the man page for more information.</p>
 
1023
 */
996
1024
int
997
1025
main(int argc, char** argv, char** env)
998
1026
{
1080
1108
      {
1081
1109
        signal(sym, ihandler);
1082
1110
      }
1083
 
#ifndef __MINGW__
 
1111
#ifndef __MINGW32__
1084
1112
    signal(SIGPIPE, SIG_IGN);
1085
1113
    signal(SIGTTOU, SIG_IGN);
1086
1114
    signal(SIGTTIN, SIG_IGN);
1102
1130
     */
1103
1131
    [[NSFileHandle fileHandleWithStandardInput] closeFile];
1104
1132
    [[NSFileHandle fileHandleWithStandardOutput] closeFile];
1105
 
#ifndef __MINGW__
 
1133
#ifndef __MINGW32__
1106
1134
    if (debugging == NO)
1107
1135
      {
1108
1136
        [[NSFileHandle fileHandleWithStandardError] closeFile];