int main(int argc, char **argv) { char *cp, **ap; int ch, disc; FILE *wfd = NULL; char *dialerstring = 0, buf[BUFSIZ]; int unitnum, keepal = 0, outfill = 0; char unitname[32]; char *password; char *upscript = NULL, *downscript = NULL; int first = 1, tries = 0; time_t fintimeout; long lpid; pid_t pid; struct termios t; int result; while ((ch = getopt(argc, argv, "dhlb:s:t:w:A:U:D:W:K:O:S:L")) != -1) switch (ch) { case 'd': debug = 1; break; case 'b': speed = atoi(optarg); break; case 's': if (diali >= MAXDIALS) errx(1, "max dial strings number (%d) exceeded", MAXDIALS); dials[diali++] = strdup(optarg); break; case 't': script_timeout = atoi(optarg); break; case 'w': wait_time = atoi(optarg); break; case 'W': MAXTRIES = atoi(optarg); break; case 'A': annex = strdup(optarg); break; case 'U': upscript = strdup(optarg); break; case 'D': downscript = strdup(optarg); break; case 'L': uucp_lock = 1; break; case 'l': modem_control = 0; break; case 'h': flowcontrol = FC_HW; break; case 'K': keepal = atoi(optarg); break; case 'O': outfill = atoi(optarg); break; case 'S': sl_unit = atoi(optarg); break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc != 3) usage(); /* * Copy these so they exist after we clobber them. */ devicename = strdup(argv[0]); username = strdup(argv[1]); password = strdup(argv[2]); /* * Security hack. Do not want private information such as the * password and possible phone number to be left around. * So we clobber the arguments. */ for (ap = argv - optind + 1; ap < argv + 3; ap++) for (cp = *ap; *cp != 0; cp++) *cp = '\0'; openlog("startslip", LOG_PID|LOG_PERROR, LOG_DAEMON); if (debug) setbuf(stdout, NULL); signal(SIGTERM, sigterm); if ((dvname = strrchr(devicename, '/')) == NULL) dvname = devicename; else dvname++; result = snprintf(my_pidfile, sizeof(my_pidfile), PIDFILE, _PATH_VARRUN, dvname); if (result < 0 || (unsigned int)result >= sizeof(my_pidfile)) usage(); if ((pfd = fopen(my_pidfile, "r")) != NULL) { if (fscanf(pfd, "%ld\n", &lpid) == 1) { pid = lpid; if (pid == lpid && pid > 0) kill(pid, SIGTERM); } fclose(pfd); pfd = NULL; /* not remove pidfile yet */ sleep(5); /* allow down script to be completed */ } else restart: signal(SIGHUP, SIG_IGN); signal(SIGURG, SIG_IGN); hup = 0; if (wfd) { printd("fclose, "); fclose(wfd); conn_time = time(NULL) - start_time; if (uucp_lock) uu_unlock(dvname); locked = 0; wfd = NULL; fd = -1; sleep(5); } else if (fd >= 0) { printd("close, "); close(fd); conn_time = time(NULL) - start_time; if (uucp_lock) uu_unlock(dvname); locked = 0; fd = -1; sleep(5); } if (logged_in) { syslog(LOG_INFO, "%s: connection time elapsed: %ld secs", username, (long)conn_time); sprintf(buf, "LINE=%d %s %s down", diali ? (dialc - 1) % diali : 0, downscript ? downscript : "/sbin/ifconfig" , unitname); system(buf); logged_in = 0; } if (terminate) down(0); tries++; if (MAXTRIES > 0 && tries > MAXTRIES) { syslog(LOG_ERR, "%s: exiting login after %d tries", username, tries); /* ??? if (first) */ down(3); } if (tries > 1) { syslog(LOG_INFO, "%s: sleeping %d seconds (%d tries)", username, wait_time * (tries - 1), tries); sleep(wait_time * (tries - 1)); if (terminate) goto restart; } if (daemon(1, debug) < 0) { syslog(LOG_ERR, "%s: daemon: %m", username); down(2); } pid = getpid(); printd("restart: pid %ld: ", (long)pid); if ((pfd = fopen(my_pidfile, "w")) != NULL) { fprintf(pfd, "%ld\n", (long)pid); fclose(pfd); } printd("open"); if (uucp_lock) { int res; if ((res = uu_lock(dvname)) != UU_LOCK_OK) { if (res != UU_LOCK_INUSE) syslog(LOG_ERR, "uu_lock: %s", uu_lockerr(res)); syslog(LOG_ERR, "%s: can't lock %s", username, devicename); goto restart; } locked = 1; } if ((fd = open(devicename, O_RDWR | O_NONBLOCK)) < 0) { syslog(LOG_ERR, "%s: open %s: %m", username, devicename); if (first) down(1); else { if (uucp_lock) uu_unlock(dvname); locked = 0; goto restart; } } printd(" %d", fd); signal(SIGHUP, sighup); if (ioctl(fd, TIOCSCTTY, 0) < 0) { syslog(LOG_ERR, "%s: ioctl (TIOCSCTTY): %m", username); down(2); } if (tcsetpgrp(fd, getpid()) < 0) { syslog(LOG_ERR, "%s: tcsetpgrp failed: %m", username); down(2); } printd(", ioctl\n"); if (tcgetattr(fd, &t) < 0) { syslog(LOG_ERR, "%s: tcgetattr(%s): %m", username, devicename); down(2); } cfmakeraw(&t); switch (flowcontrol) { case FC_HW: t.c_cflag |= (CRTS_IFLOW|CCTS_OFLOW); break; case FC_NONE: t.c_cflag &= ~(CRTS_IFLOW|CCTS_OFLOW); break; } if (modem_control) t.c_cflag |= HUPCL; else t.c_cflag &= ~(HUPCL); t.c_cflag |= CLOCAL; /* until modem commands passes */ cfsetispeed(&t, speed); cfsetospeed(&t, speed); if (tcsetattr(fd, TCSAFLUSH, &t) < 0) { syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename); down(2); } sleep(2); /* wait for flakey line to settle */ if (hup || terminate) goto restart; wfd = fdopen(fd, "w+"); if (wfd == NULL) { syslog(LOG_ERR, "%s: can't fdopen %s: %m", username, devicename); down(2); } setbuf(wfd, NULL); if (diali > 0) dialerstring = dials[dialc++ % diali]; if (dialerstring) { syslog(LOG_INFO, "%s: dialer string: %s\\r", username, dialerstring); fprintf(wfd, "%s\r", dialerstring); } printd("\n"); fintimeout = time(NULL) + script_timeout; if (modem_control) { printd("waiting for carrier\n"); while (time(NULL) < fintimeout && !carrier()) { sleep(1); if (hup || terminate) goto restart; } if (!carrier()) goto restart; t.c_cflag &= ~(CLOCAL); if (tcsetattr(fd, TCSANOW, &t) < 0) { syslog(LOG_ERR, "%s: tcsetattr(%s): %m", username, devicename); down(2); } /* Only now we able to receive HUP on carrier drop! */ } /* * Log in */ printd("look for login: "******"slip\r"); printd("Sent \"slip\"\n"); continue; } if (bcmp(&buf[1], "sername:", 8) == 0) { fprintf(wfd, "%s\r", username); printd("Sent login: %s\n", username); continue; } if (bcmp(&buf[1], "assword:", 8) == 0) { fprintf(wfd, "%s\r", password); printd("Sent password: %s\n", password); break; } } else { if (strstr(&buf[1], "ogin:") != NULL) { fprintf(wfd, "%s\r", username); printd("Sent login: %s\n", username); continue; } if (strstr(&buf[1], "assword:") != NULL) { fprintf(wfd, "%s\r", password); printd("Sent password: %s\n", password); break; } } } sleep(5); /* Wait until login completed */ if (hup || terminate) goto restart; start_time = time(NULL); /* * Attach */ printd("setd"); disc = SLIPDISC; if (ioctl(fd, TIOCSETD, &disc) < 0) { syslog(LOG_ERR, "%s: ioctl (%s, TIOCSETD): %m", username, devicename); down(2); } if (sl_unit >= 0 && ioctl(fd, SLIOCSUNIT, &sl_unit) < 0) { syslog(LOG_ERR, "%s: ioctl(SLIOCSUNIT): %m", username); down(2); } if (ioctl(fd, SLIOCGUNIT, &unitnum) < 0) { syslog(LOG_ERR, "%s: ioctl(SLIOCGUNIT): %m", username); down(2); } sprintf(unitname, "sl%d", unitnum); if (keepal > 0) { signal(SIGURG, sigurg); if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) { syslog(LOG_ERR, "%s: ioctl(SLIOCSKEEPAL): %m", username); down(2); } } if (outfill > 0 && ioctl(fd, SLIOCSOUTFILL, &outfill) < 0) { syslog(LOG_ERR, "%s: ioctl(SLIOCSOUTFILL): %m", username); down(2); } sprintf(buf, "LINE=%d %s %s up", diali ? (dialc - 1) % diali : 0, upscript ? upscript : "/sbin/ifconfig" , unitname); system(buf); printd(", ready\n"); if (!first) syslog(LOG_INFO, "%s: reconnected on %s (%d tries)", username, unitname, tries); else syslog(LOG_INFO, "%s: connected on %s", username, unitname); first = 0; tries = 0; logged_in = 1; while (hup == 0 && terminate == 0) { sigpause(0L); printd("sigpause return\n"); } goto restart; return(0); /* not reached */ }
void BinaryFunction::unsafe_merge(const Ob dep) { POMAGMA_ASSERT5(support().contains(dep), "unsupported dep: " << dep); Ob rep = carrier().find(dep); POMAGMA_ASSERT5(support().contains(rep), "unsupported rep: " << rep); POMAGMA_ASSERT4(rep != dep, "self merge: " << dep << "," << rep); // Note: in some cases, triples may move multiple times, e.g. // (dep, dep) --> (dep, rep) --> (rep, rep) // dep as rhs for (auto iter = iter_rhs(dep); iter.ok(); iter.next()) { Ob lhs = *iter; auto dep_iter = m_values.find(std::make_pair(lhs, dep)); Ob dep_val = dep_iter->second; m_values.erase(dep_iter); m_lines.Lx(lhs, dep).zero(); Ob& rep_val = m_values[std::make_pair(lhs, rep)]; if (carrier().set_or_merge(rep_val, dep_val)) { m_lines.Lx(lhs, rep).one(); } } { DenseSet dep_set(item_dim(), m_lines.Rx(dep)); DenseSet rep_set(item_dim(), m_lines.Rx(rep)); rep_set.merge(dep_set); } // dep as lhs rep = carrier().find(rep); for (auto iter = iter_lhs(dep); iter.ok(); iter.next()) { Ob rhs = *iter; auto dep_iter = m_values.find(std::make_pair(dep, rhs)); Ob dep_val = dep_iter->second; m_values.erase(dep_iter); m_lines.Rx(dep, rhs).zero(); Ob& rep_val = m_values[std::make_pair(rep, rhs)]; if (carrier().set_or_merge(rep_val, dep_val)) { m_lines.Rx(rep, rhs).one(); } } { DenseSet dep_set(item_dim(), m_lines.Lx(dep)); DenseSet rep_set(item_dim(), m_lines.Lx(rep)); rep_set.merge(dep_set); } // values must be updated in batch by update_values }
// policy: callback whenever i~k but not j~k void BinaryRelation::unsafe_merge (Ob i) { Ob j = carrier().find(i); POMAGMA_ASSERT4(j < i, "BinaryRelation tried to merge item with self"); DenseSet diff(item_dim()); DenseSet rep(item_dim(), nullptr); DenseSet dep(item_dim(), nullptr); // merge rows (i, _) into (j, _) dep.init(m_lines.Lx(i)); _remove_Rx(i, dep); rep.init(m_lines.Lx(j)); if (rep.merge(dep, diff)) { for (auto k = diff.iter(); k.ok(); k.next()) { _insert_Rx(j, *k); } } // merge cols (_, i) into (_, j) dep.init(m_lines.Rx(i)); _remove_Lx(dep, i); rep.init(m_lines.Rx(j)); if (rep.merge(dep, diff)) { for (auto k = diff.iter(); k.ok(); k.next()) { _insert_Lx(*k, j); } } }
void SymmetricFunction::update_values() const { for (auto& pair : m_values) { Ob& dep = pair.second; Ob rep = carrier().find(dep); if (rep != dep) { dep = rep; } } }
void test_function (size_t size, rng_t & rng) { Carrier carrier(size, merge_callback); random_init(carrier, rng); Example example(carrier); remove_deps(carrier, example.fun); test_merge(carrier, rng); remove_deps(carrier, example.fun); }
void SymmetricFunction::unsafe_merge(const Ob dep) { POMAGMA_ASSERT5(support().contains(dep), "unsupported dep: " << dep); Ob rep = carrier().find(dep); POMAGMA_ASSERT5(support().contains(rep), "unsupported rep: " << rep); POMAGMA_ASSERT4(rep != dep, "self merge: " << dep << "," << rep); // (dep, dep) -> (rep, rep) if (defined(dep, dep)) { auto dep_iter = m_values.find(std::make_pair(dep, dep)); Ob dep_val = dep_iter->second; m_values.erase(dep_iter); m_lines.Lx(dep, dep).zero(); Ob& rep_val = m_values[std::make_pair(rep, rep)]; if (carrier().set_or_merge(rep_val, dep_val)) { m_lines.Lx(rep, rep).one(); } } // (dep, rhs) --> (rep, rhs) for rhs != dep rep = carrier().find(rep); for (auto iter = iter_lhs(dep); iter.ok(); iter.next()) { Ob rhs = *iter; auto dep_iter = m_values.find(make_sorted_pair(dep, rhs)); Ob dep_val = dep_iter->second; m_values.erase(dep_iter); m_lines.Rx(dep, rhs).zero(); Ob& rep_val = m_values[make_sorted_pair(rep, rhs)]; if (carrier().set_or_merge(rep_val, dep_val)) { m_lines.Rx(rep, rhs).one(); } } DenseSet dep_set(item_dim(), m_lines.Lx(dep)); DenseSet rep_set(item_dim(), m_lines.Lx(rep)); rep_set.merge(dep_set); // values must be updated in batch by update_values }
inline void SymmetricFunction::insert(Ob lhs, Ob rhs, Ob val) const { SharedLock lock(m_mutex); POMAGMA_ASSERT5(support().contains(lhs), "unsupported lhs: " << lhs); POMAGMA_ASSERT5(support().contains(rhs), "unsupported rhs: " << rhs); POMAGMA_ASSERT5(support().contains(val), "unsupported val: " << val); if (carrier().set_or_merge(value(lhs, rhs), val)) { m_lines.Lx(lhs, rhs).one(); m_lines.Rx(lhs, rhs).one(); m_Vlr_table.insert(lhs, rhs, val); m_Vlr_table.insert(rhs, lhs, val); m_VLr_table.insert(lhs, rhs, val); m_VLr_table.insert(rhs, lhs, val); m_insert_callback(this, lhs, rhs); } }
FatalErrorInFunction << "solids requested, but object is not allocated" << abort(FatalError); } return solids_(); } Foam::label Foam::SLGThermo::carrierId ( const word& cmptName, bool allowNotfound ) const { forAll(carrier().species(), i) { if (cmptName == carrier_->species()[i]) { return i; } } if (!allowNotfound) { FatalErrorInFunction << "Unknown carrier component " << cmptName << ". Valid carrier components are:" << nl << carrier_->species() << exit(FatalError); }
bool Solid::Control::WiredNetworkInterface::carrier() const { Q_D(const WiredNetworkInterface); return_SOLID_CALL(Ifaces::WiredNetworkInterface *, d->backendObject(), false, carrier()); }
QString QNetworkInfoPrivate::macAddress(QNetworkInfo::NetworkMode mode, int interface) { switch (mode) { case QNetworkInfo::WlanMode: { QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*WLAN_MASK()); if (interface < dirs.size()) { QFile carrier(*NETWORK_SYSFS_PATH() + dirs.at(interface) + QString(QStringLiteral("/address"))); if (carrier.open(QIODevice::ReadOnly)) return QString::fromLatin1(carrier.readAll().simplified().data()); } break; } case QNetworkInfo::EthernetMode: { QStringList dirs = QDir(*NETWORK_SYSFS_PATH()).entryList(*ETHERNET_MASK()); if (interface < dirs.size()) { QFile carrier(*NETWORK_SYSFS_PATH() + dirs.at(interface) + QString(QStringLiteral("/address"))); if (carrier.open(QIODevice::ReadOnly)) return QString::fromLatin1(carrier.readAll().simplified().data()); } break; } case QNetworkInfo::BluetoothMode: { #if !defined(QT_NO_BLUEZ) int ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (ctl < 0) break; struct hci_dev_list_req *deviceList = (struct hci_dev_list_req *)malloc(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t)); deviceList->dev_num = HCI_MAX_DEV; QString macAddress; if (ioctl(ctl, HCIGETDEVLIST, deviceList) == 0) { int count = deviceList->dev_num; if (interface < count) { struct hci_dev_info deviceInfo; deviceInfo.dev_id = (deviceList->dev_req + interface)->dev_id; if (ioctl(ctl, HCIGETDEVINFO, &deviceInfo) == 0) { // do not use BDADDR_ANY, fails with gcc 4.6 bdaddr_t bdaddr_any = (bdaddr_t) {{0, 0, 0, 0, 0, 0}}; if (hci_test_bit(HCI_RAW, &deviceInfo.flags) && !bacmp(&deviceInfo.bdaddr, &bdaddr_any)) { int hciDevice = hci_open_dev(deviceInfo.dev_id); hci_read_bd_addr(hciDevice, &deviceInfo.bdaddr, 1000); hci_close_dev(hciDevice); } char address[18]; ba2str(&deviceInfo.bdaddr, address); macAddress = QString::fromLatin1(address); } } } free(deviceList); close(ctl); return macAddress; #else break; #endif // QT_NO_BLUEZ } // case QNetworkInfo::GsmMode: // case QNetworkInfo::CdmaMode: // case QNetworkInfo::WcdmaMode: // case QNetworkInfo::WimaxMode: // case QNetworkInfo::LteMode: // case QNetworkInfo::TdscdmaMode: default: break; }; return QString(); }
static int near Process_Modem_Response(char *rsp) { int gotbaud=FALSE; int gotarq=FALSE; char *s; if (eqstri(rsp, PRM(m_ring))) { if (*PRM(m_answer)) mdm_cmd(PRM(m_answer)); } else if (eqstrni(rsp, PRM(m_connect), strlen(PRM(m_connect)))) { baud=0L; *arq_info='\0'; /* Now parse all of the junk out of the connect string */ for (s=rsp+strlen(PRM(m_connect)); *s; ) { if (*s==' ') /* Do nothing */ s++; else if (*s=='V' && !gotarq) /* DigiDial "CONNECT V120 57600" messages */ { char *space=strchr(s, ' '); if (space) { strncpy(arq_info, s+1, space-s-1); arq_info[space-s-1]=0; gotarq=TRUE; s=space+1; } else s++; } else if (eqstrni(rsp,"fast",4)) { if (!gotbaud) { baud=9600L; s += 4; gotbaud=TRUE; } else s++; } else if (isdigit(*s)) { if (!gotbaud) { baud=atol(s); while (isdigit(*s)) s++; gotbaud=TRUE; } else s++; } else if (*s=='/' && !gotarq) { gotarq=TRUE; strnncpy(arq_info, ++s, ARQ_LEN-1); } else s++; } if (!baud) baud=300L; else if (baud==1275L || baud==75 || baud==7512L || baud==212L || baud==12L) { baud=1200L; } /* Set the right baud rate on that com port */ mdm_baud(current_baud=Decimal_Baud_To_Mask((unsigned int)baud)); local=FALSE; logit(log_wfc_connect, baud, *arq_info ? " (" : blank_str, arq_info, *arq_info ? ")" : blank_str); Update_Status(wfc_connected); /* If we get a pipe, VMP or telnet connection, it should be * instantaneous. However, due to an SIO 1.4x bug, we need * to give the line a bit of time to settle. */ if (eqstri(arq_info, "pipe") || stristr(arq_info, "/vmp") || stristr(arq_info, "/tel")) { Delay(20); } else { Mdm_Flow(FLOW_OFF); /* Wait five secs or until we get two <cr>s or <esc>s */ Clear_MNP_Garbage(); mdm_dump(DUMP_ALL); Mdm_Flow(FLOW_ON); } #ifdef UNIX /* On UNIX we need to tell the comm api that our device has a carrier else WFC will be dancing with "No carrier" */ mdm_nowonline(); #endif if (!carrier()) { logit(log_byebye); /* Reinitialize the modem */ WFC_Init_Modem(); Update_Status(wfc_waiting); baud=0L; *arq_info='\0'; /* local=TRUE;*/ return 0; } #ifdef OS_2 ComWatchDog(hcModem, TRUE, 5); /* enable, 5 sec timeout */ #endif return 1; } return 0; }