VirtualBox

Ignore:
Timestamp:
Aug 16, 2016 1:09:11 PM (8 years ago)
Author:
vboxsync
Message:

Runtime/NetBSD: re-import rtProcInitExePath-netbsd.cpp on top of an
svn copy of the FreeBSD version it's based on.

KERN_PROC_PATHNAME is only in NetBSD-current, so can't use it.

From Haomai Wang GSoC project with additional changes by Arto Huusko.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp

    r63550 r63554  
    11/* $Id$ */
    22/** @file
    3  * IPRT - rtProcInitName, FreeBSD.
     3 * IPRT - rtProcInitName, NetBSD.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2016 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath)
    4848{
    49 #ifdef KERN_PROC_PATHNAME
    50     int aiName[4];
    51     aiName[0] = CTL_KERN;
    52     aiName[1] = KERN_PROC;
    53     aiName[2] = KERN_PROC_PATHNAME;     /* This was introduced in FreeBSD 6.0, thus the #ifdef above. */
    54     aiName[3] = -1;                     /* Shorthand for the current process. */
    55 
    56     size_t cchExePath = cchPath;
    57     if (sysctl(aiName, RT_ELEMENTS(aiName), pszPath, &cchExePath, NULL, 0) == 0)
    58     {
    59         const char *pszTmp;
    60         int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    61         AssertMsgRCReturn(rc, ("rc=%Rrc pszPath=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, cchExePath, pszPath), rc);
    62         if (pszTmp != pszPath)
    63         {
    64             rc = RTStrCopy(pszPath, cchPath, pszTmp);
    65             rtPathFreeIprt(pszTmp, pszPath);
    66         }
    67         return rc;
    68     }
    69 
    70     int rc = RTErrConvertFromErrno(errno);
    71     AssertMsgFailed(("rc=%Rrc errno=%d cchExePath=%d\n", rc, errno, cchExePath));
    72     return rc;
    73 
    74 #else
    75 
    7649    /*
    7750     * Read the /proc/curproc/file link, convert to native and return it.
    7851     */
    79     int cchLink = readlink("/proc/curproc/file", pszPath, cchPath - 1);
     52    int cchLink = readlink("/proc/curproc/exe", pszPath, cchPath - 1);
    8053    if (cchLink > 0 && (size_t)cchLink <= cchPath - 1)
    8154    {
     
    8356
    8457        char const *pszTmp;
    85         int rc = rtPathFromNative(&pszTmp, pszPath);
     58        int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
    8659        AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, cchLink, pszPath), rc);
    8760        if (pszTmp != pszPath)
    8861        {
    8962            rc = RTStrCopy(pszPath, cchPath, pszTmp);
    90             rtPathFreeIprt(pszTmp);
     63            rtPathFreeIprt(pszTmp, pszPath);
    9164        }
    9265        return rc;
     
    12598    AssertMsgFailed(("rc=%Rrc err=%d cchLink=%d hExe=%p\n", rc, err, cchLink, hExe));
    12699    return rc;
    127 #endif
    128100}
    129 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette