void amiga_init (char *dir) { if ((DefaultPubScreen = LockPubScreen (0)) == 0) exit (1); screen_ratio (DefaultPubScreen); char prog_name[256]; static char font_name[MAXFONTPATH]; char *font_desc, *name_ptr; static WORD pens[] = {-1}; static struct TextAttr font = {NULL, 0, FS_NORMAL, 0}; int window = 0; if (Icon == NULL) { if (GetProgramName (prog_name, 256)) Icon = GetDiskObject (prog_name); } if (Icon) { if (FindToolType (Icon->do_ToolTypes, "WINDOW")) window = 1; if (font_desc = FindToolType (Icon->do_ToolTypes, "FONT")) { strcpy (font_name, font_desc); if (name_ptr = strrchr (font_name, '/')) { font.ta_Name = font_name; font.ta_YSize = atoi (name_ptr + 1); strcpy (name_ptr, ".font"); } } if (font.ta_Name) Font = OpenDiskFont (&font); } if (Font == NULL) { font.ta_Name = "topaz.font"; font.ta_YSize = 8; Font = OpenFont (&font); } if (window == 0) { if ((Screen = OpenScreenTags (0, SA_Pens, pens, SA_DisplayID, GetVPModeID (&DefaultPubScreen->ViewPort), SA_Overscan, OSCAN_TEXT, SA_Depth, 2, SA_Type, CUSTOMSCREEN | AUTOSCROLL, SA_Font, &font, SA_Title, TitleBar, TAG_DONE)) == 0) exit (1); } if ((Window = OpenWindowTags (0, WA_Left, 0, WA_Top, Screen ? 2 : DefaultPubScreen->BarHeight + 1, WA_Width, Screen ? Screen->Width : ScreenWidth, WA_Height, Screen ? Screen->Height - 2 : ScreenHeight - DefaultPubScreen->BarHeight - 1, WA_SmartRefresh, 1, WA_NewLookMenus, 1, WA_AutoAdjust, 1, WA_Borderless, Screen ? 1 : 0, WA_Backdrop, Screen ? 1 : 0, WA_Activate, 1, WA_CloseGadget, Screen ? 0 : 1, WA_DragBar, Screen ? 0 : 1, WA_DepthGadget, Screen ? 0 : 1, WA_SizeGadget, Screen ? 0 : 1, WA_SizeBBottom, Screen ? 0 : 1, WA_Title, TitleBar, WA_ScreenTitle, TitleBar, WA_IDCMP, IDCMP_RAWKEY | IDCMP_VANILLAKEY | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_CHANGEWINDOW, Screen ? WA_CustomScreen : WA_PubScreen, Screen ? Screen : DefaultPubScreen, TAG_DONE)) == 0) exit (1); ThisProcess = (struct Process *)FindTask(0); OldWindowPtr = ThisProcess->pr_WindowPtr; ThisProcess->pr_WindowPtr = Window; if ((Visual = GetVisualInfo (Window->WScreen, TAG_DONE)) == 0) exit (1); if ((Menus = CreateMenus (NewMenus, GTMN_NewLookMenus, TRUE, TAG_DONE)) == 0) exit (1); LayoutMenus (Menus, Visual, GTMN_NewLookMenus, TRUE, TAG_DONE); SetMenuStrip (Window, Menus); if ((GameReq = alloc_freq (dir)) == 0) exit (1); if ((SaveReq = alloc_freq (dir)) == 0) exit (1); if ((ScriptReq = alloc_freq (dir)) == 0) exit (1); RastPort = Window->RPort; SetDrMd (RastPort, JAM2); SetAPen (RastPort, 1); SetBPen (RastPort, 0); SetFont (RastPort, Font); DisplayHeight = ((Window->Height - Window->BorderTop - Window->BorderBottom) / RastPort->TxHeight) - 1; PreviousHeight = DisplayHeight; reset_cursor (); }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ EndExecution /*e*/ // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Cleans up the program void CProgram::EndExecution() { AssertThrow_(mProgramState==kRunning || mProgramState==kPaused); // Clear all the remaining stack frames - thus releasing this programs memory pool ULinkedListHelpers::DeleteAllData(&mStackFrames); // flush the events to clear all the input which has accumulated whilst in play ::FlushEvents(kUserInputEventMask,0); // Stop all sounds UKaboom::Reset(); // mMADDriver.Reset(); UFuse::ShutDown(); UTNTMapManager::ShutDown(); UButtonManager::ResetButtons(); UCursorManager::ShowCursor(); CInputManager::SuspendInput(); UGammaManager::Shutdown(); // UMusicManager::CleanUp(); UFileManager::Shutdown(); UTNTMusicManager::ResetEngine(); delete mGraphicsContext; mGraphicsContext=0L; // Reset the PC and DC mPC=mCode; mDC=mRootScope.DataStatements(); mProgramState=kReady; ECHO("Ended execution of program '" << GetProgramName() << "'"); }
void SetDefaultName( CTEXTSTR path, CTEXTSTR name, CTEXTSTR extra ) { TEXTCHAR *newpath; size_t len; static CTEXTSTR filepath;// = GetProgramPath(); static CTEXTSTR filename;// = GetProgramName(); if( path ) { if( filepath ) Release( (POINTER)filepath ); filepath = StrDup( path ); } if( name ) { if( filename ) Release( (POINTER)filename ); filename = StrDup( name ); } if( !filepath ) filepath = ExpandPath( WIDE("*/") ); if( !filename ) filename = StrDup( GetProgramName() ); if( !filename ) filename = "org.d3x0r.sack"; // this has to come from C heap.. my init isn't done yet probably and // sharemem will just fai(*syslog_local). (it's probably trying to log... ) newpath = (TEXTCHAR*)malloc( len = sizeof(TEXTCHAR)*(9 + StrLen( filepath ) + StrLen( filename ) + (extra?StrLen(extra):0) + 5) ); #ifdef __cplusplus_cli tnprintf( newpath, len, WIDE("%s/%s%s.cli.log"), filepath, filename, extra?extra:WIDE("") ); #else tnprintf( newpath, len, WIDE("%s/%s%s.log"), filepath, filename, extra?extra:WIDE("") ); #endif gFilename = newpath;//( newpath ); // use the C heap. //free( newpath ); // get rid of this ... }
void DecodeSelf( void ) { CTEXTSTR progname = GetProgramName(); FILE *self; if( decode.first_section ) { self = fopen( progname, "rb" ); if( self ) { POINTER out; uint32_t section_length; struct section section; char *filename; fseek( self, decode.first_section, SEEK_SET ); while( fread( §ion_length, 1, sizeof( section_length ), self ) ) { fread( §ion, 1, section_length, self ); filename = (char*)Allocate( section.length ); fread( filename, 1, section.length, self ); out = OpenSpace( filename, NULL, 0 ); fread( out, 1, section.library_length, self ); if( section.flags & SECTION_FLAG_STARTUP ) { decode.startup_library = filename; filename = NULL; } Release( out ); if( filename ) Release( filename ); } fclose( self ); } } }
static const char *fullprogpath(void) { static char path[MAXPATHLEN*2]; static char prog[MAXPATHLEN]; BPTR dir; extern BOOL from_WB; /* in main.c */ // If the program name contains ':' or '/' it's not in the user's path // and probably set by using Py_SetProgramName. In that case, just // use this. If it exists! strcpy(path,Py_GetProgramName()); if(strchr(path,':') || strchr(path,'/')) { if(!isxfile(path)) { // Error; the specified file does not exist or is no exe path[0]='\0'; } return path; } // Construct the full path of our executable program. if(from_WB) { /* We're launced from WB, GetProgramName() won't work */ /* Use WB's argv[0] as the executable path */ int argc; char **argv; Py_GetArgcArgv(&argc, &argv); if(argc>0) strcpy(path,argv[0]); else strcpy(path,"!error!"); } else { /* Launced from CLI, use GetProgramName */ /* However, first check if the specified name exists */ if(!isxfile(path)) { path[0]='\0'; return path; } path[0]=0; if(dir=GetProgramDir()) { (void)NameFromLock(dir,path,MAXPATHLEN); if(!GetProgramName(prog,MAXPATHLEN)) // this is a dos.library function! strcpy(prog,"!error!"); if(!AddPart(path,prog,MAXPATHLEN*2)) strcpy(path,"!error!"); } } return path; }
PRIORITY_PRELOAD( ImageRegisterInterface, IMAGE_PRELOAD_PRIORITY ) { RegisterInterface( WIDE("vulkan.image"), (void*(CPROC*)(void))GetImageInterface, (void(CPROC*)(void*))DropImageInterface ); RegisterInterface( WIDE("vulkan.image.3d"), GetImage3dInterface, DropImage3dInterface ); l.scale = (RCOORD)SACK_GetProfileInt( GetProgramName(), WIDE("SACK/Image Library/Scale"), 10 ); if( l.scale == 0.0 ) { l.scale = (RCOORD)SACK_GetProfileInt( GetProgramName(), WIDE("SACK/Image Library/Inverse Scale"), 2 ); if( l.scale == 0.0 ) l.scale = 1; } else l.scale = 1.0f / l.scale; // this initializes some of the interface methods //SetBlotMethod( BLOT_C ); RealImageInterface._IsImageTargetFinal = IsImageTargetFinal; }
void ShowVersion() { char name[128]; char message[1024]; GetProgramName(name, sizeof(name)); mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING_DOTS); lpprintf("%s\n", message); }
static void ComputeProgramCHECKSUM() { unsigned char checksum[16]; FileChecksum(GetProgramName(), checksum); for (size_t i = 0, j = 0; i < 16; ++i, j+=2) { s_program_checksum[j] = s_alphabet[checksum[i] >> 4]; s_program_checksum[j+1] = s_alphabet[checksum[i] & 0xF]; } s_program_checksum[32] = '\0'; }
void PrintUsage() { char name[128]; GetProgramName(name, sizeof(name)); lpprintf(Translate("%s usage:\n"), name); lpprintf(Translate("%s <command> [<param> [<param> [...]]].\n"), name); lpprintf(Translate("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name); lpprintf(Translate("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1); }
PRIORITY_PRELOAD( ImageRegisterInterface, IMAGE_PRELOAD_PRIORITY ) { RegisterInterface( WIDE("d3d.image"), _ImageGetImageInterface, _ImageDropImageInterface ); #ifndef __NO_OPTIONS__ l.scale = (RCOORD)SACK_GetProfileInt( GetProgramName(), WIDE("SACK/Image Library/Scale"), 10 ); if( l.scale == 0.0 ) { l.scale = (RCOORD)SACK_GetProfileInt( GetProgramName(), WIDE("SACK/Image Library/Inverse Scale"), 2 ); if( l.scale == 0.0 ) l.scale = 1; } else l.scale = 1.0f / l.scale; #else l.scale = 1.0f; #endif // this initializes some of the interface methods //SetBlotMethod( BLOT_C ); RealImageInterface._IsImageTargetFinal = IsImageTargetFinal; }
int CMTDAdmOptions::CheckArguments(void) { CActionRequest server_desc; server_desc.SetProtocolName("mtd"); try { server_desc.SetQualifiedName(GetArgCommand()); } catch(...) { if(IsVerbose()) { if(IsError == false) fprintf(stderr,"\n"); fprintf(stderr,"%s: %s\n", (const char*)GetProgramName(), (const char*)ErrorSystem.GetLastError()); IsError = true; } return(SO_OPTS_ERROR); } if(server_desc.GetAction() == NULL) { if(IsVerbose()) { if(IsError == false) fprintf(stderr,"\n"); fprintf(stderr,"%s: no action is specified\n", (const char*)GetProgramName()); IsError = true; } return(SO_OPTS_ERROR); } if((server_desc.GetAction() != "info") && (server_desc.GetAction() != "shutdown") && (server_desc.GetAction() != "errors") && (server_desc.GetAction() != "get") && (server_desc.GetAction() != "flush")) { if(IsVerbose()) { if(IsError == false) fprintf(stderr,"\n"); fprintf(stderr,"%s: specified action '%s' is not supported\n", (const char*)GetProgramName(), (const char*)server_desc.GetAction()); IsError = true; } return(SO_OPTS_ERROR); } return(SO_CONTINUE); }
SaneWinMain( argc, argv ) { // doesn't matter... if( argc > (1) && StrCaseCmp( argv[1], WIDE("install") ) == 0 ) { ServiceInstall( GetProgramName() ); return 0; } if( argc > (1) && StrCaseCmp( argv[1], WIDE("uninstall") ) == 0 ) { ServiceUninstall( GetProgramName() ); return 0; } if( LoadPrivateFunction( WIDE("sack.msgsvr.service.plugin"), NULL ) ) { SetupService( (TEXTSTR)GetProgramName(), Start ); } else lprintf( WIDE("Failed to load message core service.\n") ); return 0; }
va_dcl #else NLM_EXTERN MsgAnswer CDECL Nlm_Message (Nlm_Int2 sevkey, const char *fmt, ...) #endif { const char *caption = GetProgramName(); MsgKey key = KEY_OK; ErrSev sev = SEV_INFO; MsgAnswer ans; if (sevkey < KEY_other) { key = (MsgKey) sevkey; } else { switch (sevkey) { case MSG_ERROR : Nlm_Beep(); sev = SEV_ERROR; break; case MSG_FATAL : Nlm_Beep(); sev = SEV_MAX; break; case MSG_POSTERR : Nlm_Beep(); sev = SEV_ERROR; key = KEY_NONE; break; case MSG_POST : key = KEY_NONE; break; } } {{ const Nlm_Char PNTR scratch_str = NULL; Nlm_Char PNTR message; TSPRINTF(scratch_str, fmt); message = Nlm_StringSave(scratch_str); ans = message ? MsgAlertStr(key, sev, caption, message) : ANS_NONE; Nlm_MemFree(message); }} if (sevkey == MSG_FATAL) AbnormalExit(1); return ans; }
void ApplicationListDlg::OnInsertApplBtn() { TCHAR path[MAX_PATH]; //Stop editing item if (IsEditing()) EndEdit(); //No file at the moment *path = 0; //Browse for a new program name if (GetProgramName(path, MAX_PATH) && (FindProgram(path)==-1 || (locMessageBox(m_hDlg, IDS_PROGRAMINLIST_ERROR, IDS_ERROR, MB_OK|MB_ICONEXCLAMATION), FALSE))) InsertProgram(path, m_defaultValue); }
int main(int argc, char *argv[]) { struct FileInfoBlock fib; UBYTE buf[256]; BPTR lock; BOOL ok; ok = GetProgramName(buf, 255); Printf("%08lx %s\n", ok, buf); lock = GetProgramDir(); ok = Examine(lock, &fib); Printf("%08lx %s\n", ok, fib.fib_FileName); return 0; }
char *archdep_program_name(void) { static char *program_name = NULL; if (program_name == NULL) { char *p, name[1024]; GetProgramName(name, 1024); p = FilePart(name); if (p != NULL) { program_name = lib_stralloc(p); } } return program_name; }
long wxLuaDebuggerBase::StartClient() { if (m_debuggeeProcess == NULL) { m_debuggeeProcess = new wxLuaDebuggerProcess(this, ID_WXLUA_DEBUGGEE_PROCESS); wxString command = wxString::Format(wxT("%s -d%s:%u"), GetProgramName().c_str(), GetNetworkName().c_str(), m_port_number); m_debuggeeProcessID = wxExecute(command, wxEXEC_ASYNC|wxEXEC_MAKE_GROUP_LEADER, m_debuggeeProcess); if (m_debuggeeProcessID < 1) KillDebuggee(); } return m_debuggeeProcessID; }
void ApplicationListDlg::OnEditApplBtn() { TCHAR path[MAX_PATH]; int idx; int newidx; //Stop editing item if (IsEditing()) EndEdit(); //Get selected item index idx = ListView_GetNextItem(m_hAppListWnd, (WPARAM)-1, LVNI_SELECTED); if (idx == -1) return; //Get current program name of the item ListView_GetItemText(m_hAppListWnd, idx, 0, path, MAX_PATH); //Browse for a new program name if (GetProgramName(path, MAX_PATH) && (newidx = FindProgram(path), TRUE) && (newidx==-1 || newidx==idx || (locMessageBox(m_hDlg, IDS_PROGRAMINLIST_ERROR, IDS_ERROR, MB_OK|MB_ICONEXCLAMATION), FALSE))) InsertProgram(path, m_defaultValue, idx); }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ BeginExecution /*e*/ // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Moves the program into the executing state. You must then call Step whilst it returns true to run it. void CProgram::BeginExecution() { AssertThrow_(mProgramState==kReady); ECHO("Beginning execution of '" << GetProgramName() << "'"); // Introduce the top level stack frame CStackFrame *stack=new CStackFrame(CStackFrame::kRoot,0L,0L,mRootScope); ThrowIfMemFull_(stack); PushStackFrame(stack); mProgramState=kRunning; mBreakDisabled=false; CGLTextureManager::Initialise(); UFileManager::Initialise(this); UGammaManager::Initialise(); UTNTMapManager::Initialise(); UCursorManager::Initialise(); CProgMoanChannel::ResetSharedRegs(); CApplication::GetApplication()->ClearKeyboard(); // don't want any keys to look like they've been held down if using carbon events we could lose the keyup event }
/* Set HTTP user header */ static void x_SetupUserHeader ( SConnNetInfo* net_info, const char* appName, EMIME_Type type, EMIME_SubType subtype, EMIME_Encoding encoding ) { const char* userAgentName = NULL; char user_header [MAX_CONTENT_TYPE_LEN + 80]; /* content-type if specified */ if (type < eMIME_T_Unknown) { VERIFY( MIME_ComposeContentTypeEx (type, subtype, encoding, user_header, MAX_CONTENT_TYPE_LEN) ); ConnNetInfo_OverrideUserHeader (net_info, user_header); } /* allow the user to specify a prog. name, otherwise get it from elsewhere */ if (StringHasNoText (appName)) { const char* progName = GetProgramName(); if (StringHasNoText (progName)) { char path [PATH_MAX]; Nlm_ProgramPath (path, sizeof (path)); userAgentName = StringRChr (path, DIRDELIMCHR); if (userAgentName) ++userAgentName; } else userAgentName = progName; } else userAgentName = appName; if (StringDoesHaveText (userAgentName)) { sprintf (user_header, "User-Agent: %.80s\r\n", userAgentName); ConnNetInfo_ExtendUserHeader (net_info, user_header); } }
int CMTDAdmOptions::CheckOptions(void) { if(IsOptPasswordSet() && IsOptServerKeySet()) { if(IsError == false) fprintf(stderr,"\n"); fprintf(stderr,"%s: --password and --serverkey options are mutually exclusive\n", (char*)GetProgramName()); IsError = true; return(SO_OPTS_ERROR); } return(SO_CONTINUE); }
static char * progname(void) { #if TARGET == TARGET_UNIX #if SYSTEM == SYSTEM_AIX extern char **p_xargv; #elif SYSTEM == SYSTEM_HPUX extern char **__argv_value; #elif SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_SINIX || SYSTEM == SYSTEM_TRU64 extern char **__Argv; #elif SYSTEM == SYSTEM_UNIXWARE extern char **___Argv; #elif SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_INTERIX || \ SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_NETBSD || \ SYSTEM == SYSTEM_OPENBSD static char a[256], c[256]; ssize_t l; int f; #elif SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \ SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_LYNXOS || \ SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_SUNOS extern char **environ; char **e; char *t; #endif /* SYSTEM */ #if !MP_BUILTINSTACK_SUPPORT && !MP_GLIBCBACKTRACE_SUPPORT && \ !MP_LIBUNWIND_SUPPORT && !MP_LIBRARYSTACK_SUPPORT && \ (ARCH == ARCH_IX86 || ARCH == ARCH_M68K || ARCH == ARCH_MIPS || \ ARCH == ARCH_POWER || ARCH == ARCH_POWERPC || ARCH == ARCH_SPARC) unsigned long *p; stackinfo s; #endif /* MP_BUILTINSTACK_SUPPORT && MP_GLIBCBACKTRACE_SUPPORT && ... */ #ifdef MP_PROCFS_EXENAME static char b[64]; #endif /* MP_PROCFS_EXENAME */ #elif TARGET == TARGET_AMIGA || TARGET == TARGET_WINDOWS static char p[256]; #elif TARGET == TARGET_NETWARE char *p, *t; #endif /* TARGET */ #if TARGET == TARGET_UNIX /* AIX, HP/UX, Interix, IRIX, SINIX, Tru64 and UnixWare have global * variables containing argc and argv which we can use to determine the * filename that the program was invoked with. */ #if SYSTEM == SYSTEM_AIX if (p_xargv[0] != NULL) return p_xargv[0]; #elif SYSTEM == SYSTEM_HPUX if (__argv_value[0] != NULL) return __argv_value[0]; #elif SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_SINIX || SYSTEM == SYSTEM_TRU64 if (__Argv[0] != NULL) return __Argv[0]; #elif SYSTEM == SYSTEM_UNIXWARE if (___Argv[0] != NULL) return ___Argv[0]; #elif SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_INTERIX || \ SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_NETBSD || \ SYSTEM == SYSTEM_OPENBSD /* The BSD variants, Interix and Linux have a file in the /proc filesystem * which contains the argument vector that a process was invoked with. */ l = 0; sprintf(a, MP_PROCFS_CMDNAME, __mp_processid()); if ((f = open(a, O_RDONLY)) != -1) { if ((l = read(f, c, sizeof(c) - 1)) == -1) l = 0; close(f); } if (l > 0) { c[l] = '\0'; return c; } #elif SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \ SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_LYNXOS || \ SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_SUNOS /* We can access the argument vector from the pointer to the environment * array on all other UNIX systems. On DG/UX Intel, DRS/NX, DYNIX/ptx, * Solaris and SunOS we stop scanning backwards along the array when we * reach argc. On DG/UX M88K and LynxOS we stop scanning forwards along * the array when we reach a NULL pointer. The contents of the argument * vector then follow. */ #if (SYSTEM == SYSTEM_DGUX && ARCH == ARCH_M88K) || SYSTEM == SYSTEM_LYNXOS for (e = environ; *e != NULL; e++); t = (char *) (e + 1); #else /* SYSTEM && ARCH */ for (t = NULL, e = environ - 2; *e > (char *) _POSIX_ARG_MAX; t = *e--); #endif /* SYSTEM && ARCH */ if (t != NULL) return t; #endif /* SYSTEM */ #if !MP_BUILTINSTACK_SUPPORT && !MP_GLIBCBACKTRACE_SUPPORT && \ !MP_LIBUNWIND_SUPPORT && !MP_LIBRARYSTACK_SUPPORT && \ (ARCH == ARCH_IX86 || ARCH == ARCH_M68K || ARCH == ARCH_MIPS || \ ARCH == ARCH_POWER || ARCH == ARCH_POWERPC || ARCH == ARCH_SPARC) /* Because there is no function to return the executable filename * of a process on UNIX, we need to cheat and rely on the ABI by walking * up the process stack till we reach the startup code and then find * argv[0]. This is very OS-specific and is not my first choice for * doing this, but unfortunately it seemed to be the only way. */ __mp_newframe(&s, NULL); for (p = NULL; __mp_getframe(&s); p = (unsigned long *) s.frame); if (p != NULL) { #if ARCH == ARCH_IX86 #if SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_LINUX || \ SYSTEM == SYSTEM_NETBSD || SYSTEM == SYSTEM_OPENBSD if ((p = (unsigned long *) p[4])) return (char *) *p; #elif SYSTEM == SYSTEM_INTERIX if ((p = (unsigned long *) p[-6])) return (char *) (p + 1); #elif SYSTEM == SYSTEM_LYNXOS if ((p = (unsigned long *) p[3])) return (char *) *p; #else /* SYSTEM */ if ((p = (unsigned long *) p[3])) return (char *) p; #endif /* SYSTEM */ #elif ARCH == ARCH_M68K if ((p = (unsigned long *) p[3])) return (char *) *p; #elif ARCH == ARCH_MIPS if ((p = (unsigned long *) p[7])) return (char *) p; #elif ARCH == ARCH_POWER || ARCH == ARCH_POWERPC #if SYSTEM == SYSTEM_AIX if ((p = (unsigned long *) p[7])) return (char *) p; #else /* SYSTEM */ if ((p = (unsigned long *) p[23])) return (char *) *p; #endif /* SYSTEM */ #elif ARCH == ARCH_SPARC #if ENVIRON == ENVIRON_64 if (p = (unsigned long *) *(((unsigned long *) (*p + 0x7FF)) + 1)) #else /* ENVIRON */ if (p = (unsigned long *) *(((unsigned long *) *p) + 1)) #endif /* ENVIRON */ return (char *) *p; #endif /* ARCH */ } #endif /* MP_BUILTINSTACK_SUPPORT && MP_GLIBCBACKTRACE_SUPPORT && ... */ #ifdef MP_PROCFS_EXENAME /* If the /proc filesystem is supported then we can usually access the * actual executable file that contains the current program through a * special file in the current /proc entry. */ sprintf(b, MP_PROCFS_EXENAME, __mp_processid()); return b; #endif /* MP_PROCFS_EXENAME */ #elif TARGET == TARGET_AMIGA if (GetProgramName(p, sizeof(p))) return p; #elif TARGET == TARGET_WINDOWS if (GetModuleFileName(NULL, p, sizeof(p))) return p; #elif TARGET == TARGET_NETWARE if (GetNLMNameFromNLMID(GetNLMID(), &p, &t) == 0) return p; #endif /* TARGET */ return NULL; }
SSRVideoStreamWriter::SSRVideoStreamWriter(const std::string& channel, const std::string& source) { std::string stream_name = NumToString(hrt_time_micro()) + "-" + NumToString(getpid()) + "-" + source + "-" + GetProgramName(); m_channel_directory = "/dev/shm/ssr-" + ((channel.empty())? "channel-" + GetUserName() : channel); m_filename_main = m_channel_directory + "/video-" + stream_name; m_page_size = sysconf(_SC_PAGE_SIZE); m_width = 0; m_height = 0; m_stride = 0; m_next_frame_time = hrt_time_micro(); m_fd_main = -1; m_mmap_ptr_main = MAP_FAILED; m_mmap_size_main = 0; for(unsigned int i = 0; i < GLINJECT_RING_BUFFER_SIZE; ++i) { FrameData &fd = m_frame_data[i]; fd.m_filename_frame = m_channel_directory + "/videoframe" + NumToString(i) + "-" + stream_name; fd.m_fd_frame = -1; fd.m_mmap_ptr_frame = MAP_FAILED; fd.m_mmap_size_frame = 0; } try { Init(); } catch(...) { Free(); throw; } }
/** \brief Get absolute path to the running executable * * Free with archdep_program_path_free() on emulator exit. * * \return absolute path to running executable */ const char *archdep_program_path(void) { if (program_path != NULL) { /* already got it, return */ return program_path; } /* zero out the buffer since readlink(2) doesn't add a nul character */ memset(buffer, 0, PATH_BUFSIZE); #ifdef ARCHDEP_OS_AMIGA /* do I need a header for this? */ GetProgramName(buffer, PATH_BUFSIZE - 1); #elif defined(ARCHDEP_OS_WINDOWS) if (GetModuleFileName(NULL, buffer, PATH_BUFSIZE - 1) == PATH_BUFSIZE - 1) { log_error(LOG_ERR, "failed to retrieve executable path, falling back" " to getcwd() + argv[0]"); if (!argv_fallback()) { archdep_vice_exit(1); } } #elif defined(ARCHDEP_OS_UNIX) /* XXX: Only works on Linux and OSX, support for *BSD etc to be added later * * MacOS: _NSGetExecutablePath() * Solaris: getexecname() * FreeBSD: sysctl CTL_KERN_PROC KERN_PROC_PATHNAME - 1 (???) * NetBSD: readlink /proc/curproc/exe * DFlyBSD: readlink /proc/curproc/file * OpenBSD: ??? */ # ifdef ARCHDEP_OS_OSX /* get path via libproc */ pid_t pid = getpid(); if (proc_pidpath(pid, buffer, PATH_BUFSIZE - 1) <= 0) { log_error(LOG_ERR, "failed to retrieve executable path, falling back" " to getcwd() + argv[0]"); if (!argv_fallback()) { archdep_vice_exit(1); } } /* TODO: other Unices */ # elif defined(ARCHDEP_OS_LINUX) /* Linux as a fallback (has it really come to this?) */ if (readlink("/proc/self/exe", buffer, PATH_BUFSIZE - 1) < 0) { log_error(LOG_ERR, "failed to retrieve executable path, falling back" " to getcwd() + argv[0]"); if (!argv_fallback()) { archdep_vice_exit(1); } } /* BSD's */ # elif defined(ARCHDEP_OS_BSD) # if defined(ARCHDEP_OS_BSD_FREE) int mib[4]; size_t bufsize = PATH_BUFSIZE; /* /proc may not be available on FreeBSD */ if (readlink("/proc/curproc/file", buffer, PATH_BUFSIZE - 1) < 0) { printf("%s(): failed to read /proc/curproc/file: %d: %s\n", __func__, errno, strerror(errno)); /* try sysctl call */ mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; if (sysctl(mib, 4, buffer, &bufsize, NULL, 0) < 0) { log_error(LOG_ERR, "failed to retrieve executable path, falling back" " to getcwd() + argv[0]"); if (!argv_fallback()) { archdep_vice_exit(1); } } #if 0 printf("SYSCTL: %s\n", buffer); #endif } # elif defined(ARCHDEP_OS_BSD_NET) if (readlink("/proc/curproc/exe", buffer, PATH_BUFSIZE - 1) < 0) { log_error(LOG_ERR, "failed to retrieve executable path, falling back" " to getcwd() + argv[0]"); if (!argv_fallback()) { archdep_vice_exit(1); } } # elif defined(ARCHDEP_OS_BSD_OPEN) /* * I couldn't find any non-argv[0] solution for OpenBSD, so this will have * to do. --compyx */ if (!argv_fallback()) { archdep_vice_exit(1); } # elif defined(ARCHDEP_OS_BSD_DRAGON) # error DragonFly BSD support missing # endif /* end BSD's */ # endif /* end UNIX */ #else /* * Other systems (BeOS etc) */ if (!argv_fallback()) { archdep_vice_exit(1); } #endif program_path = lib_stralloc(buffer); #if 0 printf("%s(): program_path = %s\n", __func__, program_path); #endif return program_path; }
/* * Given a path to a jre to execute, this routine checks if this process * is indeed that jre. If not, it exec's that jre. * * We want to actually check the paths rather than just the version string * built into the executable, so that given version specification will yield * the exact same Java environment, regardless of the version of the arbitrary * launcher we start with. */ void ExecJRE(char *jre, char **argv) { int len; char path[MAXPATHLEN + 1]; const char *progname = GetProgramName(); /* * Resolve the real path to the currently running launcher. */ len = GetModuleFileName(NULL, path, MAXPATHLEN + 1); if (len == 0 || len > MAXPATHLEN) { JLI_ReportErrorMessageSys(JRE_ERROR9, progname); exit(1); } JLI_TraceLauncher("ExecJRE: old: %s\n", path); JLI_TraceLauncher("ExecJRE: new: %s\n", jre); /* * If the path to the selected JRE directory is a match to the initial * portion of the path to the currently executing JRE, we have a winner! * If so, just return. */ if (JLI_StrNCaseCmp(jre, path, JLI_StrLen(jre)) == 0) return; /* I am the droid you were looking for */ /* * If this isn't the selected version, exec the selected version. */ JLI_Snprintf(path, sizeof(path), "%s\\bin\\%s.exe", jre, progname); /* * Although Windows has an execv() entrypoint, it doesn't actually * overlay a process: it can only create a new process and terminate * the old process. Therefore, any processes waiting on the initial * process wake up and they shouldn't. Hence, a chain of pseudo-zombie * processes must be retained to maintain the proper wait semantics. * Fortunately the image size of the launcher isn't too large at this * time. * * If it weren't for this semantic flaw, the code below would be ... * * execv(path, argv); * JLI_ReportErrorMessage("Error: Exec of %s failed\n", path); * exit(1); * * The incorrect exec semantics could be addressed by: * * exit((int)spawnv(_P_WAIT, path, argv)); * * Unfortunately, a bug in Windows spawn/exec impementation prevents * this from completely working. All the Windows POSIX process creation * interfaces are implemented as wrappers around the native Windows * function CreateProcess(). CreateProcess() takes a single string * to specify command line options and arguments, so the POSIX routine * wrappers build a single string from the argv[] array and in the * process, any quoting information is lost. * * The solution to this to get the original command line, to process it * to remove the new multiple JRE options (if any) as was done for argv * in the common SelectVersion() routine and finally to pass it directly * to the native CreateProcess() Windows process control interface. */ { char *cmdline; char *p; char *np; char *ocl; char *ccl; char *unquoted; DWORD exitCode; STARTUPINFO si; PROCESS_INFORMATION pi; /* * The following code block gets and processes the original command * line, replacing the argv[0] equivalent in the command line with * the path to the new executable and removing the appropriate * Multiple JRE support options. Note that similar logic exists * in the platform independent SelectVersion routine, but is * replicated here due to the syntax of CreateProcess(). * * The magic "+ 4" characters added to the command line length are * 2 possible quotes around the path (argv[0]), a space after the * path and a terminating null character. */ ocl = GetCommandLine(); np = ccl = JLI_StringDup(ocl); p = nextarg(&np); /* Discard argv[0] */ cmdline = (char *)JLI_MemAlloc(JLI_StrLen(path) + JLI_StrLen(np) + 4); if (JLI_StrChr(path, (int)' ') == NULL && JLI_StrChr(path, (int)'\t') == NULL) cmdline = JLI_StrCpy(cmdline, path); else cmdline = JLI_StrCat(JLI_StrCat(JLI_StrCpy(cmdline, "\""), path), "\""); while (*np != (char)0) { /* While more command-line */ p = nextarg(&np); if (*p != (char)0) { /* If a token was isolated */ unquoted = unquote(p); if (*unquoted == '-') { /* Looks like an option */ if (JLI_StrCmp(unquoted, "-classpath") == 0 || JLI_StrCmp(unquoted, "-cp") == 0) { /* Unique cp syntax */ cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); p = nextarg(&np); if (*p != (char)0) /* If a token was isolated */ cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); } else if (JLI_StrNCmp(unquoted, "-version:", 9) != 0 && JLI_StrCmp(unquoted, "-jre-restrict-search") != 0 && JLI_StrCmp(unquoted, "-no-jre-restrict-search") != 0) { cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); } } else { /* End of options */ cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), np); JLI_MemFree((void *)unquoted); break; } JLI_MemFree((void *)unquoted); } } JLI_MemFree((void *)ccl); if (JLI_IsTraceLauncher()) { np = ccl = JLI_StringDup(cmdline); p = nextarg(&np); printf("ReExec Command: %s (%s)\n", path, p); printf("ReExec Args: %s\n", np); JLI_MemFree((void *)ccl); } (void)fflush(stdout); (void)fflush(stderr); /* * The following code is modeled after a model presented in the * Microsoft Technical Article "Moving Unix Applications to * Windows NT" (March 6, 1994) and "Creating Processes" on MSDN * (Februrary 2005). It approximates UNIX spawn semantics with * the parent waiting for termination of the child. */ memset(&si, 0, sizeof(si)); si.cb =sizeof(STARTUPINFO); memset(&pi, 0, sizeof(pi)); if (!CreateProcess((LPCTSTR)path, /* executable name */ (LPTSTR)cmdline, /* command line */ (LPSECURITY_ATTRIBUTES)NULL, /* process security attr. */ (LPSECURITY_ATTRIBUTES)NULL, /* thread security attr. */ (BOOL)TRUE, /* inherits system handles */ (DWORD)0, /* creation flags */ (LPVOID)NULL, /* environment block */ (LPCTSTR)NULL, /* current directory */ (LPSTARTUPINFO)&si, /* (in) startup information */ (LPPROCESS_INFORMATION)&pi)) { /* (out) process information */ JLI_ReportErrorMessageSys(SYS_ERROR1, path); exit(1); } if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) { if (GetExitCodeProcess(pi.hProcess, &exitCode) == FALSE) exitCode = 1; } else { JLI_ReportErrorMessage(SYS_ERROR2); exitCode = 1; } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); exit(exitCode); } }
void Usage( int bFull ) { if( bFull ) fprintf( stderr, WIDE("usage: %s [-f <script file>] [DSN or Sqlite db file] [-n(o headers)]\n"), GetProgramName() ); fprintf( stderr, WIDE("Command must start with '?', '!' or '='.\n") ); fprintf( stderr, WIDE("?<query> results go to the current output, or the screen if non specified before\n") ); fprintf( stderr, WIDE("!<command> - issues command to \n") ); fprintf( stderr, WIDE("=<table>@<DSN><,DSN>,...> setup output to these DSN's for next command or query result\n") ); fprintf( stderr, WIDE("?!<query> results go to the current output (with replace instead of insert), or the screen if non specified before\n") ); fprintf( stderr, WIDE("\\q on a new line - quit\n") ); }
/* * 使用指定的jvm版本来运行java程序 * * ****************************************************************************** * 函数原型: char *realpath(const char *path, char *resolved_path); * 函数说明: 用来将参数path所指的相对路径转换成绝对路径后存于参数resolved_path所指的字符串数组或指针中 * 函数返回: 成功则返回指向resolved_path的指针,失败返回NULL,错误代码存于errno * * ****************************************************************************** * 函数原型: int execve(const char * filename,char * const argv[],char * const envp[]); * 函数说明: execve用来执行参数filename字符串所代表的文件路径,第二个参数是利用数组指针来传递给执行文件,并且需要以 * 空指针(NULL)结束,最后一个参数则为传递给执行文件的新环境变量数组.exec函数一共有六个,其中execve为内核 * 级系统调用,其他(execl,execle,execlp,execv,execvp)都是调用execve的库函数 * 函数返回: 如果执行成功则函数不会返回,执行失败则直接返回-1,失败原因存于errno中 */ void ExecJRE(char *jre, char **argv) { char wanted[PATH_MAX]; const char* progname = GetProgramName(); const char* execname = NULL; /* * 转换成绝对路径 */ if (realpath(jre, wanted) == NULL) { JLI_ReportErrorMessage(JRE_ERROR9, jre); exit(1); } /* * 获取启动当前JVM进程的命令 */ SetExecname(argv); execname = GetExecName(); if (execname == NULL) { JLI_ReportErrorMessage(JRE_ERROR10); exit(1); } /* * If the path to the selected JRE directory is a match to the initial * portion of the path to the currently executing JRE, we have a winner! * If so, just return. */ if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0) return; /* I am the droid you were looking for */ /* * This should never happen (because of the selection code in SelectJRE), * but check for "impossibly" long path names just because buffer overruns * can be so deadly. */ if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) { JLI_ReportErrorMessage(JRE_ERROR11); exit(1); } /* * Construct the path and exec it. */ (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname); argv[0] = JLI_StringDup(progname); if (JLI_IsTraceLauncher()) { int i; printf("ReExec Command: %s (%s)\n", wanted, argv[0]); printf("ReExec Args:"); for (i = 1; argv[i] != NULL; i++) printf(" %s", argv[i]); printf("\n"); } JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); //刷当前进程的标准输出/错误输出流 (void)fflush(stdout); (void)fflush(stderr); //执行新的可执行程序 execv(wanted, argv); JLI_ReportErrorMessageSys(JRE_ERROR12, wanted); exit(1); }
static DWORD ParseArgs( int argc, char* argv[], DWORD* pdwAction, PSTR* ppszDomainName, PSTR* ppszName, uid_t* pUID, gid_t* pGID, bool* bForceOfflineDelete, DWORD* pdwBatchSize ) { typedef enum { PARSE_MODE_OPEN = 0, PARSE_MODE_DOMAIN_NAME, PARSE_MODE_NAME, PARSE_MODE_UID, PARSE_MODE_GID, PARSE_MODE_BATCHSIZE, PARSE_MODE_FORCE_OFFLINE_DELETE, PARSE_MODE_DONE } ParseMode; DWORD dwError = 0; int iArg = 1; PSTR pszArg = NULL; ParseMode parseMode = PARSE_MODE_OPEN; DWORD dwAction = ACTION_NONE; PSTR pszDomainName = NULL; PSTR pszName = NULL; uid_t uid = 0; gid_t gid = 0; DWORD dwBatchSize = 10; *bForceOfflineDelete = false; do { pszArg = argv[iArg++]; if (pszArg == NULL || *pszArg == '\0') { break; } switch (parseMode) { case PARSE_MODE_OPEN: if ((strcmp(pszArg, "--help") == 0) || (strcmp(pszArg, "-h") == 0)) { ShowUsage(GetProgramName(argv[0])); exit(0); } else if (!strcmp(pszArg, "--delete-all")) { dwAction = ACTION_DELETE_ALL; } else if (!strcmp(pszArg, "--delete-user")) { dwAction = ACTION_DELETE_USER; } else if (!strcmp(pszArg, "--delete-group")) { dwAction = ACTION_DELETE_GROUP; } else if (!strcmp(pszArg, "--enum-users")) { dwAction = ACTION_ENUM_USERS; } else if (!strcmp(pszArg, "--enum-groups")) { dwAction = ACTION_ENUM_GROUPS; } else if (!strcmp(pszArg, "--domain")) { parseMode = PARSE_MODE_DOMAIN_NAME; } else if (!strcmp(pszArg, "--name")) { parseMode = PARSE_MODE_NAME; } else if (!strcmp(pszArg, "--uid")) { parseMode = PARSE_MODE_UID; } else if (!strcmp(pszArg, "--gid")) { parseMode = PARSE_MODE_GID; } else if (!strcmp(pszArg, "--batchsize")) { parseMode = PARSE_MODE_BATCHSIZE; } else if (!strcmp(pszArg, "--force-offline-delete")) { parseMode = PARSE_MODE_FORCE_OFFLINE_DELETE; } else { ShowUsage(GetProgramName(argv[0])); exit(1); } break; case PARSE_MODE_DOMAIN_NAME: dwError = LwAllocateString(pszArg, &pszDomainName); BAIL_ON_LSA_ERROR(dwError); parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_NAME: dwError = LwAllocateString(pszArg, &pszName); BAIL_ON_LSA_ERROR(dwError); parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_UID: if (!IsUnsignedInteger(pszArg)) { fprintf(stderr, "Please enter a UID which is an unsigned integer.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } uid = atoi(pszArg); parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_GID: if (!IsUnsignedInteger(pszArg)) { fprintf(stderr, "Please enter a GID which is an unsigned integer.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } gid = atoi(pszArg); parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_BATCHSIZE: if (!IsUnsignedInteger(pszArg)) { fprintf(stderr, "Please enter a valid batch size.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } dwBatchSize = atoi(pszArg); if ((dwBatchSize == 0) || (dwBatchSize > 1000)) { fprintf(stderr, "Please enter a valid batch size.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_FORCE_OFFLINE_DELETE: *bForceOfflineDelete = (strcasecmp(pszArg, "true") == 0); parseMode = PARSE_MODE_OPEN; break; case PARSE_MODE_DONE: ShowUsage(GetProgramName(argv[0])); exit(1); } } while (iArg < argc); if (parseMode != PARSE_MODE_OPEN && parseMode != PARSE_MODE_DONE) { ShowUsage(GetProgramName(argv[0])); exit(1); } if ( dwAction == ACTION_NONE ) { fprintf(stderr, "Please specify a valid action.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } if ( dwAction == ACTION_DELETE_USER ) { if ( LW_IS_NULL_OR_EMPTY_STR(pszName) && !uid ) { fprintf(stderr, "Please specify name or UID.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } } if ( dwAction == ACTION_DELETE_GROUP ) { if ( LW_IS_NULL_OR_EMPTY_STR(pszName) && !gid ) { fprintf(stderr, "Please specify name or GID.\n"); ShowUsage(GetProgramName(argv[0])); exit(1); } } *pdwAction = dwAction; *ppszDomainName = pszDomainName; *ppszName = pszName; *pUID = uid; *pGID = gid; *pdwBatchSize = dwBatchSize; cleanup: return dwError; error: *pdwAction = ACTION_NONE; *ppszDomainName = NULL; *ppszName = NULL; *pUID = 0; *pGID = 0; *pdwBatchSize = 0; LW_SAFE_FREE_STRING(pszName); LW_SAFE_FREE_STRING(pszDomainName); goto cleanup; }
int ad_cache_main( int argc, char* argv[] ) { DWORD dwError = 0; HANDLE hLsaConnection = (HANDLE)NULL; size_t dwErrorBufferSize = 0; BOOLEAN bPrintOrigError = TRUE; PSTR pszOperation = "complete operation"; DWORD dwAction = ACTION_NONE; PSTR pszDomainName = NULL; PSTR pszName = NULL; uid_t uid = 0; gid_t gid = 0; bool bForceOfflineDelete; DWORD dwBatchSize = 10; if (argc < 2 || (strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)) { ShowUsage(GetProgramName(argv[0])); exit(0); } if (geteuid() != 0) { fprintf(stderr, "This program requires super-user privileges.\n"); dwError = LW_ERROR_ACCESS_DENIED; BAIL_ON_LSA_ERROR(dwError); } dwError = ParseArgs( argc, argv, &dwAction, &pszDomainName, &pszName, &uid, &gid, &bForceOfflineDelete, &dwBatchSize); BAIL_ON_LSA_ERROR(dwError); dwError = LsaOpenServer(&hLsaConnection); BAIL_ON_LSA_ERROR(dwError); switch (dwAction) { case ACTION_DELETE_ALL: pszOperation = "empty cache"; dwError = LsaAdEmptyCache( hLsaConnection, pszDomainName, bForceOfflineDelete); BAIL_ON_LSA_ERROR(dwError); fprintf(stdout, "The cache has been emptied successfully.\n"); break; case ACTION_DELETE_USER: pszOperation = "delete user"; if ( pszName ) { dwError = LsaAdRemoveUserByNameFromCache( hLsaConnection, pszDomainName, pszName); BAIL_ON_LSA_ERROR(dwError); } else { dwError = LsaAdRemoveUserByIdFromCache( hLsaConnection, pszDomainName, uid); BAIL_ON_LSA_ERROR(dwError); } fprintf(stdout, "The user has been deleted from the cache successfully.\n"); break; case ACTION_DELETE_GROUP: pszOperation = "delete group"; if ( pszName ) { dwError = LsaAdRemoveGroupByNameFromCache( hLsaConnection, pszDomainName, pszName); BAIL_ON_LSA_ERROR(dwError); } else { dwError = LsaAdRemoveGroupByIdFromCache( hLsaConnection, pszDomainName, gid); BAIL_ON_LSA_ERROR(dwError); } fprintf(stdout, "The group has been deleted from the cache successfully.\n"); break; case ACTION_ENUM_USERS: pszOperation = "enumerate users"; dwError = EnumerateUsers( hLsaConnection, pszDomainName, dwBatchSize); BAIL_ON_LSA_ERROR(dwError); break; case ACTION_ENUM_GROUPS: pszOperation = "enumerate groups"; dwError = EnumerateGroups( hLsaConnection, pszDomainName, dwBatchSize); BAIL_ON_LSA_ERROR(dwError); break; } cleanup: if (hLsaConnection != (HANDLE)NULL) { LsaCloseServer(hLsaConnection); } return dwError; error: dwError = MapErrorCode(dwError); dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0); if (dwErrorBufferSize > 0) { DWORD dwError2 = 0; PSTR pszErrorBuffer = NULL; dwError2 = LwAllocateMemory( dwErrorBufferSize, (PVOID*)&pszErrorBuffer); if (!dwError2) { DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize); if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer)) { fprintf(stderr, "Failed to %s. Error code %u (%s).\n%s\n", pszOperation, dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)), pszErrorBuffer); bPrintOrigError = FALSE; } } LW_SAFE_FREE_STRING(pszErrorBuffer); } if (bPrintOrigError) { fprintf(stderr, "Failed to %s. Error code %u (%s).\n", pszOperation, dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError))); } goto cleanup; }
static void arch_debug_load(void) { BPTR fh; char prog_name[64]; char *buf = NULL; ULONG val; int buf_size, buf_pos; int table_size; int hunk; int hunk_type; int first_hunk; int last_hunk; int guard; if (arch_debug_loaded) return; arch_debug_loaded = 1; if (!(GetProgramName(prog_name,sizeof(prog_name)))) return; if (!(fh = Open(prog_name,MODE_OLDFILE))) goto bailout; Seek(fh,0,OFFSET_END); buf_size = Seek(fh,0,OFFSET_BEGINNING); if (!(buf = (char*)malloc(buf_size))) goto bailout; if (Read(fh,buf,buf_size) != buf_size) goto bailout; buf_pos = 0; #define CHECK_EOF {if (buf_pos >= buf_size) goto bailout;} #define GET_ULONG {CHECK_EOF; val = (*(ULONG*)&buf[buf_pos]); buf_pos+=4;} GET_ULONG; if (val != HUNK_HEADER) goto bailout; GET_ULONG; if (val != 0) goto bailout; GET_ULONG; table_size = val; GET_ULONG; first_hunk = val; GET_ULONG; last_hunk = val; buf_pos += table_size * 4; CHECK_EOF; for (guard = 0, hunk = first_hunk;hunk <= last_hunk && guard < 1000; guard++) { SM_DEBUGF(20,("Scanning hunk %d\n",hunk)); GET_ULONG; hunk_type = val & 0x3FFFFFFF; switch (hunk_type) { case HUNK_DEBUG: { int lwd; int next_hunk_buf_pos; ULONG hunk_size; ULONG base_offset; GET_ULONG; hunk_size = val; next_hunk_buf_pos = buf_pos + hunk_size * 4; GET_ULONG; base_offset = val; for (lwd = 0; lwd < 20 && lwd < hunk_size; lwd++) { GET_ULONG; /* type of debug info */ switch (val) { case MAKE_ID('S','R','C',' '): break; case MAKE_ID('L','I','N','E'): { int name_size; char *name; GET_ULONG; name_size = val; name = mystrdup((char*)&buf[buf_pos]); buf_pos += name_size * 4; while(buf_pos < next_hunk_buf_pos && guard < 1000) { ULONG line, junk; struct debug_info dbi; GET_ULONG; line = val; GET_ULONG; junk = val; dbi.filename = name; dbi.line = line & 0xffffff; dbi.offset = junk + base_offset; arch_debug_info_add(&dbi); } } break; } } buf_pos = next_hunk_buf_pos; } break; case HUNK_CODE: case HUNK_DATA: case HUNK_NAME: { ULONG hunk_size; GET_ULONG; hunk_size = val; buf_pos += hunk_size * 4; } break; case HUNK_RELOC32: case HUNK_SYMBOL: { ULONG num_relocs; do { GET_ULONG; num_relocs = val; if (num_relocs) { /* Skip the number of relocs plus the hunk to which they refer */ buf_pos += num_relocs * 4 + 4; } } while (num_relocs); } break; case HUNK_END: hunk++; break; default: goto bailout; } } if (debug_info_count) { struct debug_info *di; struct debug_info dummy; dummy.offset = 0; dummy.line = 0; dummy.filename = ""; arch_debug_info_add(&dummy); dummy.offset = 0x7fffff; arch_debug_info_add(&dummy); qsort(debug_info_array,debug_info_count, sizeof(debug_info_array[0]), debug_info_cmp); } bailout: free(buf); if (fh) Close(fh); }