nsresult nsProfileCollector::LogOS(nsIMetricsEventItem *profile) { nsCOMPtr<nsIWritablePropertyBag2> properties; nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties)); NS_ENSURE_STATE(properties); char buf[SYS_INFO_BUFFER_LENGTH]; if (PR_GetSystemInfo(PR_SI_SYSNAME, buf, sizeof(buf)) != PR_SUCCESS) { MS_LOG(("Failed to get OS name")); return NS_ERROR_FAILURE; } properties->SetPropertyAsACString(NS_LITERAL_STRING("name"), nsDependentCString(buf)); MS_LOG(("Logged os name=%s", buf)); if (PR_GetSystemInfo(PR_SI_RELEASE, buf, sizeof(buf)) != PR_SUCCESS) { MS_LOG(("Failed to get OS version")); return NS_ERROR_FAILURE; } properties->SetPropertyAsACString(NS_LITERAL_STRING("version"), nsDependentCString(buf)); MS_LOG(("Logged os version=%s", buf)); nsresult rv = nsMetricsUtils::AddChildItem( profile, NS_LITERAL_STRING("os"), properties); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
NS_IMETHODIMP nsDNSService::GetMyHostName(nsACString &result) { char name[100]; if (PR_GetSystemInfo(PR_SI_HOSTNAME, name, sizeof(name)) == PR_SUCCESS) { result = name; return NS_OK; } return NS_ERROR_FAILURE; }
PRIntn main(PRIntn argc, char **argv) { PRStatus rv; PRSysInfo cmd; PRFileDesc *output = PR_GetSpecialFD(PR_StandardOutput); char *info = (char*)PR_Calloc(SYS_INFO_BUFFER_LENGTH, 1); for (cmd = PR_SI_HOSTNAME; cmd <= PR_SI_ARCHITECTURE; Incr(&cmd)) { rv = PR_GetSystemInfo(cmd, info, SYS_INFO_BUFFER_LENGTH); if (PR_SUCCESS == rv) PR_fprintf(output, "%s: %s\n", tag[cmd], info); else PL_FPrintError(output, tag[cmd]); } PR_DELETE(info); PR_fprintf(output, "Host page size is %d\n", PR_GetPageSize()); PR_fprintf(output, "Page shift is %d\n", PR_GetPageShift()); PR_fprintf(output, "Number of processors is: %d\n", PR_GetNumberOfProcessors()); return 0; } /* main */
nsresult nsSystemInfo::Init() { nsresult rv = nsHashPropertyBag::Init(); NS_ENSURE_SUCCESS(rv, rv); static const struct { PRSysInfo cmd; const char *name; } items[] = { { PR_SI_SYSNAME, "name" }, { PR_SI_HOSTNAME, "host" }, { PR_SI_ARCHITECTURE, "arch" }, { PR_SI_RELEASE, "version" } }; for (PRUint32 i = 0; i < (sizeof(items) / sizeof(items[0])); i++) { char buf[SYS_INFO_BUFFER_LENGTH]; if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) { rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name), nsDependentCString(buf)); NS_ENSURE_SUCCESS(rv,rv); } else NS_WARNING("PR_GetSystemInfo failed"); } #ifdef MOZ_WIDGET_GTK2 // This must be done here because NSPR can only separate OS's when compiled, not libraries. char* gtkver = PR_smprintf("GTK %u.%u.%u", gtk_major_version, gtk_minor_version, gtk_micro_version); if (gtkver) { rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16("secondaryLibrary"), nsDependentCString(gtkver)); PR_smprintf_free(gtkver); NS_ENSURE_SUCCESS(rv, rv); } #endif return NS_OK; }
nsresult nsProfileCollector::LogCPU(nsIMetricsEventItem *profile) { nsCOMPtr<nsIWritablePropertyBag2> properties; nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties)); NS_ENSURE_STATE(properties); char buf[SYS_INFO_BUFFER_LENGTH]; if (PR_GetSystemInfo(PR_SI_ARCHITECTURE, buf, sizeof(buf)) != PR_SUCCESS) { MS_LOG(("Failed to get architecture")); return NS_ERROR_FAILURE; } properties->SetPropertyAsACString(NS_LITERAL_STRING("arch"), nsDependentCString(buf)); MS_LOG(("Logged CPU arch=%s", buf)); nsresult rv = nsMetricsUtils::AddChildItem( profile, NS_LITERAL_STRING("cpu"), properties); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
nsresult nsProfileLock::LockWithSymlink(nsIFile *aLockFile, bool aHaveFcntlLock) { nsresult rv; nsAutoCString lockFilePath; rv = aLockFile->GetNativePath(lockFilePath); if (NS_FAILED(rv)) { NS_ERROR("Could not get native path"); return rv; } // don't replace an existing lock time if fcntl already got one if (!mReplacedLockTime) aLockFile->GetLastModifiedTimeOfLink(&mReplacedLockTime); struct in_addr inaddr; inaddr.s_addr = htonl(INADDR_LOOPBACK); char hostname[256]; PRStatus status = PR_GetSystemInfo(PR_SI_HOSTNAME, hostname, sizeof hostname); if (status == PR_SUCCESS) { char netdbbuf[PR_NETDB_BUF_SIZE]; PRHostEnt hostent; status = PR_GetHostByName(hostname, netdbbuf, sizeof netdbbuf, &hostent); if (status == PR_SUCCESS) memcpy(&inaddr, hostent.h_addr, sizeof inaddr); } char *signature = PR_smprintf("%s:%s%lu", inet_ntoa(inaddr), aHaveFcntlLock ? "+" : "", (unsigned long)getpid()); const char *fileName = lockFilePath.get(); int symlink_rv, symlink_errno = 0, tries = 0; // use ns4.x-compatible symlinks if the FS supports them while ((symlink_rv = symlink(signature, fileName)) < 0) { symlink_errno = errno; if (symlink_errno != EEXIST) break; if (!IsSymlinkStaleLock(&inaddr, fileName, aHaveFcntlLock)) break; // Lock seems to be bogus: try to claim it. Give up after a large // number of attempts (100 comes from the 4.x codebase). (void) unlink(fileName); if (++tries > 100) break; } PR_smprintf_free(signature); signature = nullptr; if (symlink_rv == 0) { // We exclusively created the symlink: record its name for eventual // unlock-via-unlink. rv = NS_OK; mHaveLock = true; mPidLockFileName = strdup(fileName); if (mPidLockFileName) { PR_APPEND_LINK(this, &mPidLockList); if (!setupPidLockCleanup++) { // Clean up on normal termination. // This instanciates a dummy class, and will trigger the class // destructor when libxul is unloaded. This is equivalent to atexit(), // but gracefully handles dlclose(). static RemovePidLockFilesExiting r; // Clean up on abnormal termination, using POSIX sigaction. // Don't arm a handler if the signal is being ignored, e.g., // because mozilla is run via nohup. if (!sDisableSignalHandling) { struct sigaction act, oldact; #ifdef SA_SIGINFO act.sa_sigaction = FatalSignalHandler; act.sa_flags = SA_SIGINFO; #else act.sa_handler = FatalSignalHandler; #endif sigfillset(&act.sa_mask); #define CATCH_SIGNAL(signame) \ PR_BEGIN_MACRO \ if (sigaction(signame, nullptr, &oldact) == 0 && \ oldact.sa_handler != SIG_IGN) \ { \ sigaction(signame, &act, &signame##_oldact); \ } \ PR_END_MACRO CATCH_SIGNAL(SIGHUP); CATCH_SIGNAL(SIGINT); CATCH_SIGNAL(SIGQUIT); CATCH_SIGNAL(SIGILL); CATCH_SIGNAL(SIGABRT); CATCH_SIGNAL(SIGSEGV); CATCH_SIGNAL(SIGTERM); #undef CATCH_SIGNAL } } } } else if (symlink_errno == EEXIST) rv = NS_ERROR_FILE_ACCESS_DENIED; else { #ifdef DEBUG printf("symlink() failed. errno = %d\n", errno); #endif rv = NS_ERROR_FAILURE; } return rv; }
nsresult XRemoteClient::GetLock(Window aWindow, bool *aDestroyed) { bool locked = false; bool waited = false; *aDestroyed = false; nsresult rv = NS_OK; if (!mLockData) { char pidstr[32]; char sysinfobuf[SYS_INFO_BUFFER_LENGTH]; PR_snprintf(pidstr, sizeof(pidstr), "pid%d@", getpid()); PRStatus status; status = PR_GetSystemInfo(PR_SI_HOSTNAME, sysinfobuf, SYS_INFO_BUFFER_LENGTH); if (status != PR_SUCCESS) { return NS_ERROR_FAILURE; } // allocate enough space for the string plus the terminating // char mLockData = (char *)malloc(strlen(pidstr) + strlen(sysinfobuf) + 1); if (!mLockData) return NS_ERROR_OUT_OF_MEMORY; strcpy(mLockData, pidstr); if (!strcat(mLockData, sysinfobuf)) return NS_ERROR_FAILURE; } do { int result; Atom actual_type; int actual_format; unsigned long nitems, bytes_after; unsigned char *data = 0; XGrabServer(mDisplay); result = XGetWindowProperty (mDisplay, aWindow, mMozLockAtom, 0, (65536 / sizeof (long)), False, /* don't delete */ XA_STRING, &actual_type, &actual_format, &nitems, &bytes_after, &data); // aWindow may have been destroyed before XSelectInput was processed, in // which case there may not be any DestroyNotify event in the queue to // tell us. XGetWindowProperty() was synchronous so error responses have // now been processed, setting sGotBadWindow. if (sGotBadWindow) { *aDestroyed = true; rv = NS_ERROR_FAILURE; } else if (result != Success || actual_type == None) { /* It's not now locked - lock it. */ XChangeProperty (mDisplay, aWindow, mMozLockAtom, XA_STRING, 8, PropModeReplace, (unsigned char *)mLockData, strlen(mLockData)); locked = True; } XUngrabServer(mDisplay); XFlush(mDisplay); // ungrab now! if (!locked && !NS_FAILED(rv)) { /* We tried to grab the lock this time, and failed because someone else is holding it already. So, wait for a PropertyDelete event to come in, and try again. */ PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("window 0x%x is locked by %s; waiting...\n", (unsigned int) aWindow, data)); waited = True; while (1) { XEvent event; int select_retval; fd_set select_set; struct timeval delay; delay.tv_sec = 10; delay.tv_usec = 0; FD_ZERO(&select_set); // add the x event queue to the select set FD_SET(ConnectionNumber(mDisplay), &select_set); select_retval = select(ConnectionNumber(mDisplay) + 1, &select_set, nullptr, nullptr, &delay); // did we time out? if (select_retval == 0) { PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("timed out waiting for window\n")); rv = NS_ERROR_FAILURE; break; } PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("xevent...\n")); XNextEvent (mDisplay, &event); if (event.xany.type == DestroyNotify && event.xdestroywindow.window == aWindow) { *aDestroyed = true; rv = NS_ERROR_FAILURE; break; } else if (event.xany.type == PropertyNotify && event.xproperty.state == PropertyDelete && event.xproperty.window == aWindow && event.xproperty.atom == mMozLockAtom) { /* Ok! Someone deleted their lock, so now we can try again. */ PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("(0x%x unlocked, trying again...)\n", (unsigned int) aWindow)); break; } } } if (data) XFree(data); } while (!locked && !NS_FAILED(rv)); if (waited && locked) { PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("obtained lock.\n")); } else if (*aDestroyed) { PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("window 0x%x unexpectedly destroyed.\n", (unsigned int) aWindow)); } return rv; }
/************************************************************************* * * P k 1 1 I n s t a l l _ D o I n s t a l l * * jarFile is the path of a JAR in the PKCS #11 module JAR format. * installDir is the directory relative to which files will be * installed. */ Pk11Install_Error Pk11Install_DoInstall(char *jarFile, const char *installDir, const char *tempDir, PRFileDesc *feedback, short force, PRBool noverify) { JAR *jar; char *installer; unsigned long installer_len; int status; Pk11Install_Error ret; PRBool made_temp_file; Pk11Install_Info installInfo; Pk11Install_Platform *platform; char *errMsg; char sysname[SYS_INFO_BUFFER_LENGTH], release[SYS_INFO_BUFFER_LENGTH], arch[SYS_INFO_BUFFER_LENGTH]; char *myPlatform; jar = NULL; ret = PK11_INSTALL_UNSPECIFIED; made_temp_file = PR_FALSE; errMsg = NULL; Pk11Install_Info_init(&installInfo); /* printf("Inside DoInstall, jarFile=%s, installDir=%s, tempDir=%s\n", jarFile, installDir, tempDir); */ /* * Check out jarFile and installDir for validity */ if (PR_Access(installDir, PR_ACCESS_EXISTS) != PR_SUCCESS) { error(PK11_INSTALL_DIR_DOESNT_EXIST, installDir); return PK11_INSTALL_DIR_DOESNT_EXIST; } if (!tempDir) { tempDir = "."; } if (PR_Access(tempDir, PR_ACCESS_EXISTS) != PR_SUCCESS) { error(PK11_INSTALL_DIR_DOESNT_EXIST, tempDir); return PK11_INSTALL_DIR_DOESNT_EXIST; } if (PR_Access(tempDir, PR_ACCESS_WRITE_OK) != PR_SUCCESS) { error(PK11_INSTALL_DIR_NOT_WRITEABLE, tempDir); return PK11_INSTALL_DIR_NOT_WRITEABLE; } if ((PR_Access(jarFile, PR_ACCESS_EXISTS) != PR_SUCCESS)) { error(PK11_INSTALL_FILE_DOESNT_EXIST, jarFile); return PK11_INSTALL_FILE_DOESNT_EXIST; } if (PR_Access(jarFile, PR_ACCESS_READ_OK) != PR_SUCCESS) { error(PK11_INSTALL_FILE_NOT_READABLE, jarFile); return PK11_INSTALL_FILE_NOT_READABLE; } /* * Extract the JAR file */ jar = JAR_new(); JAR_set_callback(JAR_CB_SIGNAL, jar, jar_callback); if (noverify) { status = JAR_pass_archive_unverified(jar, jarArchGuess, jarFile, "url"); } else { status = JAR_pass_archive(jar, jarArchGuess, jarFile, "url"); } if ((status < 0) || (jar->valid < 0)) { if (status >= JAR_BASE && status <= JAR_BASE_END) { error(PK11_INSTALL_JAR_ERROR, jarFile, JAR_get_error(status)); } else { error(PK11_INSTALL_JAR_ERROR, jarFile, mySECU_ErrorString(PORT_GetError())); } ret = PK11_INSTALL_JAR_ERROR; goto loser; } /*printf("passed the archive\n");*/ /* * Show the user security information, allow them to abort or continue */ if (Pk11Install_UserVerifyJar(jar, PR_STDOUT, force ? PR_FALSE : PR_TRUE) && !force) { if (feedback) { PR_fprintf(feedback, msgStrings[USER_ABORT]); } ret = PK11_INSTALL_USER_ABORT; goto loser; } /* * Get the name of the installation file */ if (JAR_get_metainfo(jar, NULL, INSTALL_METAINFO_TAG, (void **)&installer, (unsigned long *)&installer_len)) { error(PK11_INSTALL_NO_INSTALLER_SCRIPT); ret = PK11_INSTALL_NO_INSTALLER_SCRIPT; goto loser; } if (feedback) { PR_fprintf(feedback, msgStrings[INSTALLER_SCRIPT_NAME], installer); } /* * Extract the installation file */ if (PR_Access(SCRIPT_TEMP_FILE, PR_ACCESS_EXISTS) == PR_SUCCESS) { if (PR_Delete(SCRIPT_TEMP_FILE) != PR_SUCCESS) { error(PK11_INSTALL_DELETE_TEMP_FILE, SCRIPT_TEMP_FILE); ret = PK11_INSTALL_DELETE_TEMP_FILE; goto loser; } } if (noverify) { status = JAR_extract(jar, installer, SCRIPT_TEMP_FILE); } else { status = JAR_verified_extract(jar, installer, SCRIPT_TEMP_FILE); } if (status) { if (status >= JAR_BASE && status <= JAR_BASE_END) { error(PK11_INSTALL_JAR_EXTRACT, installer, JAR_get_error(status)); } else { error(PK11_INSTALL_JAR_EXTRACT, installer, mySECU_ErrorString(PORT_GetError())); } ret = PK11_INSTALL_JAR_EXTRACT; goto loser; } else { made_temp_file = PR_TRUE; } /* * Parse the installation file into a syntax tree */ Pk11Install_FD = PR_Open(SCRIPT_TEMP_FILE, PR_RDONLY, 0); if (!Pk11Install_FD) { error(PK11_INSTALL_OPEN_SCRIPT_FILE, SCRIPT_TEMP_FILE); ret = PK11_INSTALL_OPEN_SCRIPT_FILE; goto loser; } if (Pk11Install_yyparse()) { error(PK11_INSTALL_SCRIPT_PARSE, installer, Pk11Install_yyerrstr ? Pk11Install_yyerrstr : ""); ret = PK11_INSTALL_SCRIPT_PARSE; goto loser; } #if 0 /* for debugging */ Pk11Install_valueList->Print(0); #endif /* * From the syntax tree, build a semantic structure */ errMsg = Pk11Install_Info_Generate(&installInfo, Pk11Install_valueList); if (errMsg) { error(PK11_INSTALL_SEMANTIC, errMsg); ret = PK11_INSTALL_SEMANTIC; goto loser; } #if 0 installInfo.Print(0); #endif if (feedback) { PR_fprintf(feedback, msgStrings[PARSED_INSTALL_SCRIPT]); } /* * Figure out which platform to use */ { sysname[0] = release[0] = arch[0] = '\0'; if ((PR_GetSystemInfo(PR_SI_SYSNAME, sysname, SYS_INFO_BUFFER_LENGTH) != PR_SUCCESS) || (PR_GetSystemInfo(PR_SI_RELEASE, release, SYS_INFO_BUFFER_LENGTH) != PR_SUCCESS) || (PR_GetSystemInfo(PR_SI_ARCHITECTURE, arch, SYS_INFO_BUFFER_LENGTH) != PR_SUCCESS)) { error(PK11_INSTALL_SYSINFO); ret = PK11_INSTALL_SYSINFO; goto loser; } myPlatform = PR_smprintf("%s:%s:%s", sysname, release, arch); platform = Pk11Install_Info_GetBestPlatform(&installInfo, myPlatform); if (!platform) { error(PK11_INSTALL_NO_PLATFORM, myPlatform); PR_smprintf_free(myPlatform); ret = PK11_INSTALL_NO_PLATFORM; goto loser; } if (feedback) { PR_fprintf(feedback, msgStrings[MY_PLATFORM_IS], myPlatform); PR_fprintf(feedback, msgStrings[USING_PLATFORM], Pk11Install_PlatformName_GetString(&platform->name)); } PR_smprintf_free(myPlatform); } /* Run the install for that platform */ ret = DoInstall(jar, installDir, tempDir, platform, feedback, noverify); if (ret) { goto loser; } ret = PK11_INSTALL_SUCCESS; loser: if (Pk11Install_valueList) { Pk11Install_ValueList_delete(Pk11Install_valueList); PR_Free(Pk11Install_valueList); Pk11Install_valueList = NULL; } if (jar) { JAR_destroy(jar); } if (made_temp_file) { PR_Delete(SCRIPT_TEMP_FILE); } if (errMsg) { PR_smprintf_free(errMsg); } return ret; }
nsresult nsMsgMdnGenerator::CreateSecondPart() { DEBUG_MDN("nsMsgMdnGenerator::CreateSecondPart"); char *tmpBuffer = nsnull; char *convbuf = nsnull; nsresult rv = NS_OK; nsCOMPtr <nsIMsgCompUtils> compUtils; PRBool conformToStandard = PR_FALSE; tmpBuffer = PR_smprintf("--%s" CRLF, m_mimeSeparator.get()); PUSH_N_FREE_STRING(tmpBuffer); tmpBuffer = PR_smprintf("%s" CRLF, "Content-Type: message/disposition-notification; name=\042MDNPart2.txt\042"); PUSH_N_FREE_STRING(tmpBuffer); tmpBuffer = PR_smprintf("%s" CRLF, "Content-Disposition: inline"); PUSH_N_FREE_STRING(tmpBuffer); tmpBuffer = PR_smprintf("Content-Transfer-Encoding: %s" CRLF CRLF, ENCODING_7BIT); PUSH_N_FREE_STRING(tmpBuffer); nsCOMPtr<nsIHttpProtocolHandler> pHTTPHandler = do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv); if (NS_SUCCEEDED(rv) && pHTTPHandler) { nsCAutoString userAgentString; pHTTPHandler->GetUserAgent(userAgentString); if (!userAgentString.IsEmpty()) { // Prepend the product name with the dns name according to RFC 3798. char hostName[256]; PR_GetSystemInfo(PR_SI_HOSTNAME_UNTRUNCATED, hostName, sizeof hostName); if ((hostName[0] != '\0') && (strchr(hostName, '.') != NULL)) { userAgentString.Insert("; ", 0); userAgentString.Insert(nsDependentCString(hostName), 0); } tmpBuffer = PR_smprintf("Reporting-UA: %s" CRLF, userAgentString.get()); PUSH_N_FREE_STRING(tmpBuffer); } } nsCString originalRecipient; m_headers->ExtractHeader(HEADER_ORIGINAL_RECIPIENT, PR_FALSE, getter_Copies(originalRecipient)); if (!originalRecipient.IsEmpty()) { tmpBuffer = PR_smprintf("Original-Recipient: %s" CRLF, originalRecipient.get()); PUSH_N_FREE_STRING(tmpBuffer); } compUtils = do_GetService(NS_MSGCOMPUTILS_CONTRACTID, &rv); if (compUtils) compUtils->GetMsgMimeConformToStandard(&conformToStandard); convbuf = nsMsgI18NEncodeMimePartIIStr( m_email.get(), PR_TRUE, m_charset.get(), 0, conformToStandard); tmpBuffer = PR_smprintf("Final-Recipient: rfc822;%s" CRLF, convbuf ? convbuf : m_email.get()); PUSH_N_FREE_STRING(tmpBuffer); PR_Free (convbuf); if (*m_messageId.get() == '<') tmpBuffer = PR_smprintf("Original-Message-ID: %s" CRLF, m_messageId.get()); else tmpBuffer = PR_smprintf("Original-Message-ID: <%s>" CRLF, m_messageId.get()); PUSH_N_FREE_STRING(tmpBuffer); tmpBuffer = PR_smprintf("Disposition: %s/%s; %s" CRLF CRLF, (m_autoAction ? "automatic-action" : "manual-action"), (m_autoSend ? "MDN-sent-automatically" : "MDN-sent-manually"), DispositionTypes[(int) m_disposeType]); PUSH_N_FREE_STRING(tmpBuffer); return rv; }
PRIntn main(PRIntn argc, char **argv) { PRStatus rv; PLOptStatus os; PRHostEnt host; PRProtoEnt proto; PRBool ipv6 = PR_FALSE; const char *name = NULL; PRBool failed = PR_FALSE; PLOptState *opt = PL_CreateOptState(argc, argv, "h6"); err = PR_GetSpecialFD(PR_StandardError); while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { if (PL_OPT_BAD == os) continue; switch (opt->option) { case 0: /* Name of host to lookup */ name = opt->value; break; case '6': /* Turn on IPv6 mode */ ipv6 = PR_TRUE; break; case 'h': /* user wants some guidance */ default: Help(); /* so give him an earful */ return 2; /* but not a lot else */ } } PL_DestroyOptState(opt); if (ipv6) { rv = PR_SetIPv6Enable(ipv6); if (PR_FAILURE == rv) { failed = PR_TRUE; PL_FPrintError(err, "PR_SetIPv6Enable"); } } { if (NULL == name) { char *me = (char*)PR_MALLOC(DNS_BUFFER); rv = PR_GetSystemInfo(PR_SI_HOSTNAME, me, DNS_BUFFER); if (PR_FAILURE == rv) { failed = PR_TRUE; PL_FPrintError(err, "PR_GetHostName"); return 2; } name = me; /* just leak the storage */ } } { char buffer[HOST_BUFFER]; PR_fprintf(err, "Translating the name %s ...", name); rv = PR_GetHostByName(name, buffer, sizeof(buffer), &host); if (PR_FAILURE == rv) { failed = PR_TRUE; PL_FPrintError(err, "PR_GetHostByName"); } else { PRIntn index = 0; PRNetAddr address; PR_fprintf(err, "success .. enumerating results\n"); do { index = PR_EnumerateHostEnt(index, &host, 0, &address); if (index > 0) PrintAddress(&address); else if (-1 == index) { failed = PR_TRUE; PL_FPrintError(err, "PR_EnumerateHostEnt"); } } while (index > 0); } } { char buffer[PROTO_BUFFER]; /* ** Get Proto by name/number */ rv = PR_GetProtoByName("tcp", &buffer[1], sizeof(buffer) - 1, &proto); rv = PR_GetProtoByNumber(6, &buffer[3], sizeof(buffer) - 3, &proto); } return (failed) ? 1 : 0; }
nsresult nsProfileLock::LockWithSymlink(const nsACString& lockFilePath, PRBool aHaveFcntlLock) { nsresult rv; struct in_addr inaddr; inaddr.s_addr = htonl(INADDR_LOOPBACK); char hostname[256]; PRStatus status = PR_GetSystemInfo(PR_SI_HOSTNAME, hostname, sizeof hostname); if (status == PR_SUCCESS) { char netdbbuf[PR_NETDB_BUF_SIZE]; PRHostEnt hostent; status = PR_GetHostByName(hostname, netdbbuf, sizeof netdbbuf, &hostent); if (status == PR_SUCCESS) memcpy(&inaddr, hostent.h_addr, sizeof inaddr); } char *signature = PR_smprintf("%s:%s%lu", inet_ntoa(inaddr), aHaveFcntlLock ? "+" : "", (unsigned long)getpid()); const nsPromiseFlatCString& flat = PromiseFlatCString(lockFilePath); const char *fileName = flat.get(); int symlink_rv, symlink_errno = 0, tries = 0; // use ns4.x-compatible symlinks if the FS supports them while ((symlink_rv = symlink(signature, fileName)) < 0) { symlink_errno = errno; if (symlink_errno != EEXIST) break; if (!IsSymlinkStaleLock(&inaddr, fileName, aHaveFcntlLock)) break; // Lock seems to be bogus: try to claim it. Give up after a large // number of attempts (100 comes from the 4.x codebase). (void) unlink(fileName); if (++tries > 100) break; } PR_smprintf_free(signature); signature = nsnull; if (symlink_rv == 0) { // We exclusively created the symlink: record its name for eventual // unlock-via-unlink. rv = NS_OK; mHaveLock = PR_TRUE; mPidLockFileName = strdup(fileName); if (mPidLockFileName) { PR_APPEND_LINK(this, &mPidLockList); if (!setupPidLockCleanup++) { // Clean up on normal termination. atexit(RemovePidLockFilesExiting); // Clean up on abnormal termination, using POSIX sigaction. // Don't arm a handler if the signal is being ignored, e.g., // because mozilla is run via nohup. if (!sDisableSignalHandling) { struct sigaction act, oldact; #ifdef SA_SIGINFO act.sa_sigaction = FatalSignalHandler; act.sa_flags = SA_SIGINFO; #else act.sa_handler = FatalSignalHandler; #endif sigfillset(&act.sa_mask); #define CATCH_SIGNAL(signame) \ PR_BEGIN_MACRO \ if (sigaction(signame, NULL, &oldact) == 0 && \ oldact.sa_handler != SIG_IGN) \ { \ sigaction(signame, &act, &signame##_oldact); \ } \ PR_END_MACRO CATCH_SIGNAL(SIGHUP); CATCH_SIGNAL(SIGINT); CATCH_SIGNAL(SIGQUIT); CATCH_SIGNAL(SIGILL); CATCH_SIGNAL(SIGABRT); CATCH_SIGNAL(SIGSEGV); CATCH_SIGNAL(SIGTERM); #undef CATCH_SIGNAL } } } } else if (symlink_errno == EEXIST) rv = NS_ERROR_FILE_ACCESS_DENIED; else { #ifdef DEBUG printf("symlink() failed. errno = %d\n", errno); #endif rv = NS_ERROR_FAILURE; } return rv; }
char *dns_ip2host(char *ip, int verify) { /* struct in_addr iaddr; */ PRNetAddr iaddr; char *hn; static unsigned long laddr = 0; static char myhostname[256]; PRHostEnt hent; char buf[PR_NETDB_BUF_SIZE]; PRStatus err; err = PR_InitializeNetAddr(PR_IpAddrNull, 0, &iaddr); /* richm: ipv6 cleanup - use inet_aton or other more appropriate function instead of inet_addr */ if((iaddr.inet.ip = inet_addr(ip)) == (in_addr_t)-1) goto bong; /* * See if it happens to be the localhost IP address, and try * the local host name if so. */ if (laddr == 0) { laddr = inet_addr("127.0.0.1"); myhostname[0] = 0; PR_GetSystemInfo(PR_SI_HOSTNAME, myhostname, sizeof(myhostname)); } /* Have to match the localhost IP address and have a hostname */ if ((iaddr.inet.ip == laddr) && (myhostname[0] != 0)) { /* * Now try for a fully-qualified domain name, starting with * the local hostname. */ err = PR_GetHostByName(myhostname, buf, PR_NETDB_BUF_SIZE, &hent); /* Don't verify if we get a fully-qualified name this way */ verify = 0; } else { err = PR_GetHostByAddr(&iaddr, buf, PR_NETDB_BUF_SIZE, &hent); } if ((err == PR_FAILURE) || !(hn = net_find_fqdn(&hent))) goto bong; if(verify) { char **haddr = 0; err = PR_GetHostByName(hn, buf, PR_NETDB_BUF_SIZE, &hent); if(err == PR_SUCCESS) { for(haddr = hent.h_addr_list; *haddr; haddr++) { if(((struct in_addr *)(*haddr))->s_addr == iaddr.inet.ip) break; } } if((err == PR_FAILURE) || (!(*haddr))) goto bong; } return hn; bong: return NULL; }