/**************************************************************************** * * NAME: main * * FUNCTION: call jfs_logdmp() * * INTERFACE: * jfs_logdump [-a] <volume specifier> * * where -a => dump entire contents of log instead of just * committed transactions since last synch * point. * * NOTES: * * RETURNS: * success: 0 * failure: something else */ int32 main( int32 argc, char **argv ) { int32 rc = LOGDMP_OK; int32 Vol_Label_Size; rc = parse_parms( argc, argv ); /* parse the parms and record * them in the aggregate wsp record */ if( rc == LOGDMP_OK ) { /* parms are good */ rc = open_device_read ( Vol_Label ); if( rc == LOGDMP_OK ) { rc = jfs_logdump( Vol_Label, Dev_IOPort, dump_all ); } /* * Close the device */ if( device_is_open ) { rc = DosClose( Dev_IOPort ); free(ptrklay); } } /* end parms are good */ return( rc ); } /* end of main() */
int main(int argc,char* argv[]) { int makedaemon = 1; char conffile[256]; int c; signal(SIGINT,onsignal); signal(SIGHUP,onsignal); signal(SIGTERM,onsignal); //strcpy(s.authserver,DEFAULT_AUTHSERVER); strcpy(s.authserver,nvram_get("wan_bigpond_auth")); //strcpy(s.authdomain,DEFAULT_AUTHDOMAIN); strcpy(s.authdomain,nvram_get("wan_bigpond_server")); s.authport = DEFAULT_AUTHPORT; //strcpy(s.username,""); strcpy(s.username,nvram_get("wan_bigpond_username")); //strcpy(s.password,""); strcpy(s.password,nvram_get("wan_bigpond_password")); strcpy(s.connectedprog,""); strcpy(s.disconnectedprog,""); strcpy(conffile,DEFAULT_CONFFILE); strcpy(s.localaddress,""); s.localport = 0; s.minheartbeat = 60; s.maxheartbeat = 420; #if 0 while( (c = getopt( argc, argv, "c:d:l:D" )) > -1 ) { switch( c ) { case 'c': strncpy( conffile, optarg, MAXCONFFILE); break; case '?': usage(); exit(1); break; } } if(!parse_parms(&s,conffile)) { printf( "bpalogin: Could not read configuration file (%s)\n\n", conffile ); usage(); exit(1); } optind = 1; while( (c = getopt( argc, argv, "c:d:l:D" )) > -1 ) { switch( c ) { case 'D': makedaemon = 0; break; case 'c': break; case 'd': debug_level = atoi(optarg); break; case 'l': if( strcasecmp( optarg, "stdout" ) == 0 ) dosyslog = 0; else dosyslog = 1; break; case '?': break; case ':': break; } } #endif if(makedaemon) { /** * Original code did not perform the setsid() or second fork(), and * hence did not correctly make itself a daemon. There is a library * call in FreeBSD (daemon) that does the actions below, but the * portability is unknown. */ switch( fork() ) { case 0: break; case -1: perror("Could not run BPALogin in the background"); exit(1); break; default: exit(0); break; } if( setsid() < 0 ) { perror("Could not run BPALogin in the background"); exit(1); } /** * while not strictly necessary, the second fork ensures we stay * detached from a terminal by preventing the program using its * status as session leader to regain a terminal. */ switch( fork() ) { case 0: break; case -1: perror("Could not run BPALogin in the background"); exit(1); break; default: exit(0); break; } } openlog("bpalogin",LOG_PID,LOG_DAEMON); if(dosyslog) syslog( LOG_INFO, BPALOGIN_BANNER "\n" ); else printf( BPALOGIN_BANNER "\n"); if(!strcmp(s.username,"")) { critical("Username has not been set"); exit(1); } if(!strcmp(s.password,"")) { critical("Password has not been set"); exit(1); } s.debug = debug; s.critical = critical; s.noncritical = noncritical; s.onconnected = onconnected; s.ondisconnected = ondisconnected; while(mainloop(&s)); s.ondisconnected(0); exit(0); }
/*! \brief This function is called by module management in 2.6 kernel or by ifxusb_driver_init with 2.4 kernel It is to probe and setup IFXUSB core(s). */ static int ifxusb_driver_probe(struct platform_device *_dev) { int retval = 0; int *pins = _dev->dev.platform_data; if (ltq_is_vr9()) { gpio_request(6, "id1"); gpio_request(9, "id2"); gpio_direction_input(6); gpio_direction_input(9); } if (pins) { if (pins[0]) { gpio_request(pins[0], "vbus1"); gpio_direction_output(pins[0], 1); } if (pins[1] && ltq_is_vr9()) { gpio_request(pins[1], "vbus2"); gpio_direction_output(pins[1], 1); } } // Parsing and store the parameters IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ ); parse_parms(); #ifdef __IS_HOST__ #if defined(__IS_DUAL__) memset(&ifxusb_hcd_1, 0, sizeof(ifxhcd_hcd_t)); memset(&ifxusb_hcd_2, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd_1.core_if.core_no=0; ifxusb_hcd_2.core_if.core_no=1; ifxusb_hcd_1.core_if.core_name=(char *)ifxusb_hcd_name_1; ifxusb_hcd_2.core_if.core_name=(char *)ifxusb_hcd_name_2; ifxusb_hcd_1.dev=&_dev->dev; ifxusb_hcd_2.dev=&_dev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd_1, IFX_USB0_IR, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; retval = ifxusb_driver_probe_h(&ifxusb_hcd_2, IFX_USB1_IR, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #elif defined(__IS_FIRST__) memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=0; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_dev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFX_USB0_IR, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #elif defined(__IS_SECOND__) memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=1; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_dev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFX_USB1_IR, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #else memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=0; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_dev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFXUSB_IRQ, IFXUSB_IOMEM_BASE, IFXUSB_FIFOMEM_BASE, IFXUSB_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #endif #if defined(__DO_OC_INT__) IFXUSB_DEBUGPL( DBG_CIL, "registering (overcurrent) handler for irq%d\n", IFXUSB_OC_IRQ); #if defined(__IS_DUAL__) request_irq((unsigned int)IFXUSB_OC_IRQ, &ifx_hcd_oc_irq, // SA_INTERRUPT|SA_SHIRQ, "ifxusb_oc", (void *)&ifxusb_hcd_1); IRQF_DISABLED | IRQF_SHARED, "ifxusb_oc", (void *)&ifxusb_hcd_1); oc_int_id=&ifxusb_hcd_1; #else request_irq((unsigned int)IFXUSB_OC_IRQ, &ifx_hcd_oc_irq, // SA_INTERRUPT|SA_SHIRQ, "ifxusb_oc", (void *)&ifxusb_hcd); IRQF_DISABLED | IRQF_SHARED, "ifxusb_oc", (void *)&ifxusb_hcd); oc_int_id=&ifxusb_hcd; #endif oc_int_installed=1; #if defined(__DO_OC_INT_ENABLE__) ifxusb_oc_int_on(); #endif #endif #endif #ifdef __IS_DEVICE__ memset(&ifxusb_pcd, 0, sizeof(ifxpcd_pcd_t)); ifxusb_pcd.core_if.core_name=(char *)&ifxusb_pcd_name[0]; ifxusb_pcd.dev=&_dev->dev; #if defined(__IS_FIRST__) ifxusb_pcd.core_if.core_no=0; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB1_IRQ, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); #elif defined(__IS_SECOND__) ifxusb_pcd.core_if.core_no=1; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB2_IRQ, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); #else ifxusb_pcd.core_if.core_no=0; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB_IRQ, IFXUSB_IOMEM_BASE, IFXUSB_FIFOMEM_BASE, IFXUSB_FIFODBG_BASE ); #endif if(retval) goto ifxusb_driver_probe_fail; #endif ifxusb_attr_create(&_dev->dev); return 0; ifxusb_driver_probe_fail: ifxusb_driver_remove(_dev); return retval; }
/*! \brief This function is called by module management in 2.6 kernel or by ifxusb_driver_init with 2.4 kernel It is to probe and setup IFXUSB core(s). */ static int ifxusb_driver_probe(struct platform_device *_pdev) { int retval = 0; struct device_node *np; int gpio_count; u32 port_mask = 0x1; #ifdef __IS_DANUBE__ np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-danube"); #elif defined __IS_AMAZON_SE__ np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-ase"); #elif defined __IS_AR9__ np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-arx100"); #elif defined __IS_VR9__ np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-xrx200"); #elif defined __IS_AR10__ np = of_find_compatible_node(NULL, NULL, "lantiq,ifxhcd-arx300"); #endif if (!np) { dev_err(&_pdev->dev, "failed to find hcd device node\n"); return -ENODEV; } of_property_read_u32(np, "lantiq,portmask", &port_mask); // Parsing and store the parameters IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ ); parse_parms(); #ifdef __IS_HOST__ #if defined(__DO_OC_INT__) if(!oc_int_id) { #if defined(__IS_DUAL__) oc_int_id=&ifxusb_hcd_1; oc_int_id_1=&ifxusb_hcd_1; oc_int_id_2=&ifxusb_hcd_2; #else oc_int_id=&ifxusb_hcd; #endif } #endif #if defined(__IS_DUAL__) memset(&ifxusb_hcd_1, 0, sizeof(ifxhcd_hcd_t)); memset(&ifxusb_hcd_2, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd_1.core_if.core_no=0; ifxusb_hcd_2.core_if.core_no=1; ifxusb_hcd_1.core_if.core_name=(char *)ifxusb_hcd_name_1; ifxusb_hcd_2.core_if.core_name=(char *)ifxusb_hcd_name_2; ifxusb_hcd_1.dev=&_pdev->dev; ifxusb_hcd_2.dev=&_pdev->dev; if (port_mask & 0x1) { retval = ifxusb_driver_probe_h(&ifxusb_hcd_1, IFXUSB1_IRQ, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; } if (port_mask & 0x2) { retval = ifxusb_driver_probe_h(&ifxusb_hcd_2, IFXUSB2_IRQ, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; } #elif defined(__IS_FIRST__) memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=0; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_pdev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFXUSB1_IRQ, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #elif defined(__IS_SECOND__) memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=1; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_pdev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFXUSB2_IRQ, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #else memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t)); ifxusb_hcd.core_if.core_no=0; ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name; ifxusb_hcd.dev=&_pdev->dev; retval = ifxusb_driver_probe_h(&ifxusb_hcd, IFXUSB_IRQ, IFXUSB_IOMEM_BASE, IFXUSB_FIFOMEM_BASE, IFXUSB_FIFODBG_BASE ); if(retval) goto ifxusb_driver_probe_fail; #endif #endif #ifdef __IS_DEVICE__ memset(&ifxusb_pcd, 0, sizeof(ifxpcd_pcd_t)); ifxusb_pcd.core_if.core_name=(char *)&ifxusb_pcd_name[0]; ifxusb_pcd.dev=&_pdev->dev; #if defined(__IS_FIRST__) ifxusb_pcd.core_if.core_no=0; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB1_IRQ, IFXUSB1_IOMEM_BASE, IFXUSB1_FIFOMEM_BASE, IFXUSB1_FIFODBG_BASE ); #elif defined(__IS_SECOND__) ifxusb_pcd.core_if.core_no=1; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB2_IRQ, IFXUSB2_IOMEM_BASE, IFXUSB2_FIFOMEM_BASE, IFXUSB2_FIFODBG_BASE ); #else ifxusb_pcd.core_if.core_no=0; retval = ifxusb_driver_probe_d(&ifxusb_pcd, IFXUSB_IRQ, IFXUSB_IOMEM_BASE, IFXUSB_FIFOMEM_BASE, IFXUSB_FIFODBG_BASE ); #endif if(retval) goto ifxusb_driver_probe_fail; #endif /* #ifdef __IS_HOST__ ifxusb_attr_create_h(&_pdev->dev); #else ifxusb_attr_create_d(&_pdev->dev); #endif*/ gpio_count = of_gpio_count(np); while (gpio_count > 0) { enum of_gpio_flags flags; int gpio = of_get_gpio_flags(np, --gpio_count, &flags); if (gpio_request(gpio, "usb")) continue; dev_info(&_pdev->dev, "requested GPIO %d\n", gpio); gpio_direction_output(gpio, (flags & OF_GPIO_ACTIVE_LOW) ? (0) : (1)); } return 0; ifxusb_driver_probe_fail: ifxusb_driver_remove(_pdev); return retval; }
INT main (INT argc, char *argv[]) #endif { #if PC_WATCOM struct find_t info; #endif UINT n; LONG status = 0; /****/ if (argc < 2) { print_help(); exit(1); } printf( "\nRORTEST - reorient, requant, crop, join or els-code seq. jpg and pic files.\n" "(c) 1995, Pegasus Imaging Corporation, Tampa, Florida\n" ); /* Get command line arguments. */ parse_parms(argc, argv); if (!skip_copyright) show_copyright(); num_tables = 0; if (QTableName[0] != '\0') /* User supplied a file name holding Q-table values */ { /* qtable is assumed NOT in zig_zag order (unlike what's in jpg file ) */ FILE *QFile; LONG qq,u,stat = 0; int len,c; /****/ QFile = fopen(QTableName, "rt"); check(QFile != NULL, "Q-table %s could not be opened", QTableName); u = 192; if(regions) { u += u; region_qtable = (WORD *)qtable; } memset(qtable,0,u); n = 0; u = 255; if(regions) u = 65535; while(n < 192) { len = fscanf(QFile, " %d", &qq); if(len != 1) { if(len == EOF) break; c = getc(QFile); if(c == '#') { /* comment to the end of line */ while(1) { c = getc(QFile); if(c == '\n'|| c == EOF) break; } if(c == EOF) break; continue; } else break; } if(qq < 1 || qq > u) { printf("Program terminated:illegal quantization value(s)\n"); stat = -1; break; } if(regions) region_qtable[n++] = qq; else qtable[n++] = qq; } fclose(QFile); QFile = NULL; if(stat != 0) exit(1); check(n == 64 || n == 128 || n == 192, "incorrect number of quantization values"); num_tables = n/64; } #if PC_WATCOM n = 0; if (_dos_findfirst(src_name, _A_NORMAL, &info) == 0) { do { strcpy(src_name, src_path); strcat(src_name, info.name); if (wild_card) { strcpy(des_name, des_path); strcat(des_name, info.name); strcpy(strchr(des_name, '.'), des_ext); } status = expand(); n++; } while ( _dos_findnext(&info) == 0); } else printf("\n image not found.\n", n); printf("\nThere were %d images converted or attempted.\n", n); #else status = expand(); #endif if(status != 0) printf("status = %d\n",status); return (0); }
/* * Read a list of gateways from /etc/gateways and add them to our tables. * * This file contains a list of "remote" gateways. That is usually * a gateway which we cannot immediately determine if it is present or * not as we can do for those provided by directly connected hardware. * * If a gateway is marked "passive" in the file, then we assume it * does not understand RIP and assume it is always present. Those * not marked passive are treated as if they were directly connected * and assumed to be broken if they do not send us advertisements. * All remote interfaces are added to our list, and those not marked * passive are sent routing updates. * * A passive interface can also be local, hardware interface exempt * from RIP. */ void gwkludge(void) { #define STR2(x) #x #define STR(x) STR2(x) #define NETHOST_LEN 4 #define DNAME_LEN MAXHOSTNAMELEN #define GNAME_LEN MAXHOSTNAMELEN #define QUAL_LEN 8 FILE *fp; char *p, *lptr; const char *cp; char lbuf[PARMS_MAXLINELEN], net_host[NETHOST_LEN + 1]; char dname[MAXHOSTNAMELEN + 1]; char gname[MAXHOSTNAMELEN + 1], qual[QUAL_LEN +1]; struct interface *ifp; uint32_t dst, netmask, gate; int n; uint32_t lnum; struct stat sb; uint32_t state, metric; boolean_t default_dst; fp = fopen(PATH_GATEWAYS, "r"); if (fp == NULL) return; if (0 > fstat(fileno(fp), &sb)) { msglog("fstat() failed: %s for "PATH_GATEWAYS, rip_strerror(errno)); (void) fclose(fp); return; } for (lnum = 1; ; lnum++) { if (NULL == fgets(lbuf, sizeof (lbuf), fp)) break; /* Eliminate the /n character at the end of the lbuf */ if (strlen(lbuf) > 0) lbuf[strlen(lbuf) - 1] = '\0'; /* Move lptr to the first non-space character */ for (lptr = lbuf; isspace(*lptr); lptr++) ; if (*lptr == '#' || *lptr == '\0') continue; /* Move p to the end of the line */ p = lptr + strlen(lptr) - 1; /* Skip all trailing spaces except escaped space */ while (p > lptr && (isspace(*p) && *(p-1) != '\\')) p--; /* truncate the line to remove trailing spaces */ *++p = '\0'; /* notice newfangled parameter lines */ if (strncasecmp("net", lptr, 3) != 0 && strncasecmp("host", lptr, 4) != 0) { cp = parse_parms(lptr, (sb.st_uid == 0 && !(sb.st_mode&(S_IRWXG|S_IRWXO)))); if (cp != 0) msglog("%s in line %u of "PATH_GATEWAYS, cp, lnum); continue; } /* * Processes lines of the follwoing format: * net|host <name>[/mask] gateway <Gname> metric <value> * passive|active|extern */ qual[0] = '\0'; n = sscanf(lptr, "%"STR(NETHOST_LEN)"s %"STR(DNAME_LEN) "[^ \t] gateway %"STR(GNAME_LEN)"[^ / \t] metric %u %" STR(QUAL_LEN)"s\n", net_host, dname, gname, &metric, qual); if (n != 4 && n != 5) { msglog("bad "PATH_GATEWAYS" entry \"%s\"; %d values", lptr, n); continue; } if (metric >= HOPCNT_INFINITY) { msglog("bad metric in "PATH_GATEWAYS" entry \"%s\"", lptr); continue; } default_dst = _B_FALSE; if (strcasecmp(net_host, "host") == 0) { if (!gethost(dname, &dst)) { msglog("bad host \"%s\" in "PATH_GATEWAYS " entry \"%s\"", dname, lptr); continue; } netmask = HOST_MASK; } else if (strcasecmp(net_host, "net") == 0) { if (!getnet(dname, &dst, &netmask)) { msglog("bad net \"%s\" in "PATH_GATEWAYS " entry \"%s\"", dname, lptr); continue; } default_dst = (dst == RIP_DEFAULT); dst = htonl(dst); /* make network # into IP address */ } else { msglog("bad \"%s\" in "PATH_GATEWAYS " entry \"%s\"", net_host, lptr); continue; } if (!gethost(gname, &gate)) { msglog("bad gateway \"%s\" in "PATH_GATEWAYS " entry \"%s\"", gname, lptr); continue; } if (strcasecmp(qual, "passive") == 0) { /* * Passive entries are not placed in our tables, * only the kernel's, so we don't copy all of the * external routing information within a net. * Internal machines should use the default * route to a suitable gateway (like us). */ state = IS_REMOTE | IS_PASSIVE; if (metric == 0) metric = 1; } else if (strcasecmp(qual, "external") == 0) { /* * External entries are handled by other means * such as EGP, and are placed only in the daemon * tables to prevent overriding them with something * else. */ (void) strlcpy(qual, "external", sizeof (qual)); state = IS_REMOTE | IS_PASSIVE | IS_EXTERNAL; if (metric == 0) metric = 1; } else if (strcasecmp(qual, "active") == 0 || qual[0] == '\0') { if (default_dst) { msglog("bad net \"%s\" in "PATH_GATEWAYS " entry \"%s\"-- cannot be default", dname, lptr); continue; } if (metric != 0) { /* * Entries that are neither "passive" nor * "external" are "remote" and must behave * like physical interfaces. If they are not * heard from regularly, they are deleted. */ state = IS_REMOTE; } else { /* * "remote" entries with a metric of 0 * are aliases for our own interfaces */ state = IS_REMOTE | IS_PASSIVE | IS_ALIAS; } } else { msglog("bad "PATH_GATEWAYS" entry \"%s\";" " unknown type %s", lptr, qual); continue; } if (0 != (state & (IS_PASSIVE | IS_REMOTE))) state |= IS_NO_RDISC; if (state & IS_PASSIVE) state |= IS_NO_RIP; if (default_dst) { addroutefordefault(dst, gate, netmask, metric, ((state & IS_EXTERNAL)? RTS_EXTERNAL : 0)); continue; } ifp = check_dup(NULL, gate, dst, netmask, 0, _B_FALSE); if (ifp != NULL) { msglog("duplicate "PATH_GATEWAYS" entry \"%s\"", lptr); continue; } ifp = rtmalloc(sizeof (*ifp), "gwkludge()"); (void) memset(ifp, 0, sizeof (*ifp)); ifp->int_state = state; if (netmask == HOST_MASK) ifp->int_if_flags = IFF_POINTOPOINT | IFF_UP; else ifp->int_if_flags = IFF_UP; ifp->int_act_time = NEVER; ifp->int_addr = gate; ifp->int_dstaddr = dst; ifp->int_mask = netmask; ifp->int_ripv1_mask = netmask; ifp->int_std_mask = std_mask(gate); ifp->int_net = ntohl(dst); ifp->int_std_net = ifp->int_net & ifp->int_std_mask; ifp->int_std_addr = htonl(ifp->int_std_net); ifp->int_metric = metric; if (!(state & IS_EXTERNAL) && ifp->int_mask != ifp->int_std_mask) ifp->int_state |= IS_SUBNET; (void) snprintf(ifp->int_name, sizeof (ifp->int_name), "remote(%s)", gname); if_link(ifp, 0); } (void) fclose(fp); /* * After all of the parameter lines have been read, * apply them to any remote interfaces. */ for (ifp = ifnet; NULL != ifp; ifp = ifp->int_next) { get_parms(ifp); tot_interfaces++; if (!IS_RIP_OFF(ifp->int_state)) rip_interfaces++; if (!IS_RIP_OUT_OFF(ifp->int_state)) ripout_interfaces++; trace_if("Add", ifp); } }
int main(int argc, char **argv) { struct sockaddr_in client_addr; struct client *client; struct client **client_ptr; int listen_fd, connect_fd; socklen_t client_len; sigset_t set; struct sigaction action; char *shim_host_path; char *parms_path; char *debug_log_path; struct parms *parms; char *ip; // Open debug.log file debug_log_path = getenv("DEBUG_LOG_PATH"); if (!debug_log_path) debug_log_path = "debug.log"; fp = fopen(debug_log_path, "w"); if (!fp) { error_msg("Could not open debug.log"); return -1; } // Mask SIGPIPE signal for all threads sigemptyset(&set); sigaddset(&set, SIGPIPE); if (pthread_sigmask(SIG_BLOCK, &set, NULL)) { perror("pthread_sigmask"); return -1; } // Catch SIGINT for graceful termination action.sa_handler = _INThandler; sigemptyset(&(action.sa_mask)); action.sa_flags = 0; sigaction(SIGINT, &action, NULL); // Report version info_msg("PSLSE version %d.%03d compiled @ %s %s", PSLSE_VERSION_MAJOR, PSLSE_VERSION_MINOR, __DATE__, __TIME__); debug_send_version(fp, PSLSE_VERSION_MAJOR, PSLSE_VERSION_MINOR); // Parse parameters file parms_path = getenv("PSLSE_PARMS"); if (!parms_path) parms_path = "pslse.parms"; parms = parse_parms(parms_path, fp); if (parms == NULL) { error_msg("Unable to parse params file \"%s\"", parms_path); return -1; } timeout = parms->timeout; // Connect to simulator(s) and start psl thread(s) pthread_mutex_init(&lock, NULL); pthread_mutex_lock(&lock); shim_host_path = getenv("SHIM_HOST_DAT"); if (!shim_host_path) shim_host_path = "shim_host.dat"; afu_map = parse_host_data(&psl_list, parms, shim_host_path, &lock, fp); if (psl_list == NULL) { free(parms); fclose(fp); warn_msg("Unable to connect to any simulators"); return -1; } // Start server if ((listen_fd = _start_server()) < 0) { free(parms); fclose(fp); return -1; } // Watch for client connections while (psl_list != NULL) { // Wait for next client to connect client_len = sizeof(client_addr); pthread_mutex_unlock(&lock); connect_fd = accept(listen_fd, (struct sockaddr *)&client_addr, &client_len); pthread_mutex_lock(&lock); if (connect_fd < 0) { lock_delay(&lock); continue; } ip = (char *)malloc(INET_ADDRSTRLEN + 1); inet_ntop(AF_INET, &(client_addr.sin_addr.s_addr), ip, INET_ADDRSTRLEN); // Clean up disconnected clients client_ptr = &client_list; while (*client_ptr != NULL) { client = *client_ptr; if ((client->pending == 0) && (client->state == CLIENT_NONE)) { *client_ptr = client->_next; if (client->_next != NULL) client->_next->_prev = client->_prev; _free_client(client); lock_delay(&lock); continue; } client_ptr = &((*client_ptr)->_next); } // Add new client info_msg("Connection from %s", ip); client = _client_connect(&connect_fd, ip); if (client != NULL) { if (client_list != NULL) client_list->_prev = client; client->_next = client_list; client_list = client; if (pthread_create(&(client->thread), NULL, _client_loop, client)) { perror("pthread_create"); break; } } lock_delay(&lock); } info_msg("No AFUs connected, Shutting down PSLSE\n"); close_socket(&listen_fd); // Shutdown unassociated client connections while (client_list != NULL) { client = client_list; client_list = client->_next; if (client->pending) client->pending = 0; pthread_mutex_unlock(&lock); pthread_join(client->thread, NULL); pthread_mutex_lock(&lock); close_socket(&(client->fd)); _free_client(client); } pthread_mutex_unlock(&lock); free(parms); fclose(fp); pthread_mutex_destroy(&lock); return 0; }