int do_cat_pdsmember(CIFBLK *cif, DSXTENT *extent, int noext, char* dsname, char *pdsmember, unsigned long optflags) { int rc; u_int trk; U8 rec; /* Point to the start of the directory */ trk = 0; rec = 1; /* Read the directory */ while (1) { BYTE *blkptr; BYTE dirblk[256]; U32 cyl; U8 head; U16 len; EXTGUIMSG( "CTRK=%d\n", trk ); rc = convert_tt(trk, noext, extent, cif->heads, &cyl, &head); if (rc < 0) return -1; rc = read_block(cif, cyl, head, rec, 0, 0, &blkptr, &len); if (rc < 0) return -1; if (rc > 0) /* end of track */ { trk++; rec = 1; continue; } if (len == 0) /* physical end of file */ return 0; memcpy(dirblk, blkptr, sizeof(dirblk)); rc = process_dirblk(cif, noext, extent, dirblk, dsname, pdsmember, optflags); if (rc < 0) return -1; if (rc > 0) /* logical end of file */ return 0; rec++; } UNREACHABLE_CODE(); }
HRESULT WINAPI OutOfProcessExceptionEventSignatureCallback ( /* __in */ PVOID pContext, /* __in */ const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation, /* __in */ DWORD dwIndex, /* __out */ PWSTR pwszName, /* __inout */ PDWORD pchName, /* __out */ PWSTR pwszValue, /* __inout */ PDWORD pchValue ) /*++ Routine Description: WER can call this function multiple times to get the report parameters that uniquely describe the problem. The PFN_WER_RUNTIME_EXCEPTION_EVENT_SIGNATURE type defines a pointer to this callback function. This function will be exported out of this DLL, as specified by HandlerDll.def. Arguments: pContext - An arbitrary pointer-sized value that was passed in to WerRegisterRuntimeExceptionModule. pExceptionInformation - A WER_RUNTIME_EXCEPTION_INFORMATION structure that contains the exception information. dwIndex - The index of the report parameter. Valid values are 0 to 9. pwszName - A caller-allocated buffer that you use to specify the parameter name. pchName - A pointer to a DWORD specifying the size, in characters, of the pwszName buffer. The size includes the null-terminating character. pwszValue - A caller-allocated buffer that you use to specify the parameter value. pchValue - A pointer to a DWORD specifying the size, in characters, of the pwszValue buffer. The size includes the null-terminating character. Return Value: HRESULT. --*/ { UNREFERENCED_PARAMETER (pContext); // // Some sanity checks. Our handler only specifies 2 signature pairs. // if (dwIndex >= 2 || (0xABCD1234 != pExceptionInformation->exceptionRecord.ExceptionCode)) { return E_UNEXPECTED; } // // Make sure the given buffers are large enough to hold our signature name/value pairs. // We will need 4 characters (3 characters + 1 null-terminator) for our fixed strings. // if (*pchName < 4) { *pchName = 4; return HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER); } if (*pchValue < 4) { *pchValue = 4; return HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER); } // // At this point, we should fill in the problem signature with the data from the crashing process. // // For example, the signature can uniquely identify where the crash happened. If our application runs // custom-compiled code, we can let the signature identify what module/class/line/etc the crash // happened at. This can be done by exposing an easily-accessible data structure in the process, and // reading the structure using ReadProcessMemory. // // In here, we will simply set the signature to some fixed strings. // switch (dwIndex) { case 0: wcscpy_s (pwszName, *pchName, L"one"); wcscpy_s (pwszValue, *pchValue, L"111"); break; case 1: wcscpy_s (pwszName, *pchName, L"two"); wcscpy_s (pwszValue, *pchValue, L"222"); break; default: UNREACHABLE_CODE (); } return S_OK; }
int wmain ( int argc, const wchar_t* argv[], const wchar_t* envp[] ) { HRESULT hr = E_FAIL; DWORD rc; WCHAR ModulePath[MAX_PATH]; size_t i; UNREFERENCED_PARAMETER (argc); UNREFERENCED_PARAMETER (argv); UNREFERENCED_PARAMETER (envp); // // Get the full-path name to ourselves, so we can form a full-path to HandlerDll.dll in this directory: // // C:\SomeDirectory\CrashExe.exe // ^ // 1) scan until this character (the last forward slash) // 2) from that point, replace the substring with "HandlerDll.dll" to form: // // C:\SomeDirectory\HandlerDll.dll // rc = GetModuleFileName (NULL, ModulePath, MAX_PATH); if (!rc || (rc == MAX_PATH && ERROR_INSUFFICIENT_BUFFER == GetLastError ())) { return 1; } // // Find the last \, so we can replace our exe name with "HandlerDll.dll". // ModulePath[MAX_PATH-1] = 0; for (i = wcslen (ModulePath); i >= 0; --i) { if (ModulePath[i] == L'\\') { if (0 != wcscpy_s (&ModulePath[i + 1], MAX_PATH - i - 1, L"HandlerDll.dll")) { return 1; } break; } } // // Tell WER to register a custom runtime exception module for this process. // // IMPORTANT: The handler also has to be registered in the system registry by creating a special value // under the HKEY_LOCAL_MACHINE hive. Please refer to 'Running the Sample' section in README.TXT for // complete details. // wprintf (L"Registering %s as the custom exception handler.\n", ModulePath); hr = WerRegisterRuntimeExceptionModule (ModulePath, NULL); if (FAILED(hr)) { wprintf (L"Failed to register a custom exception handler: 0x%08X\n", hr); goto End; } // // Raise a custom exception. This should be handled by HandlerDll.dll. // // Note that the system will clear bit 28 of dwExceptionCode. This bit is a reserved exception bit, // used by the system for its own purposes. // // The exception we will be using through-out the example is 0xABCD1234 - its bit 28 is clear. // wprintf (L"Raising exception 0xABCD1234...\n"); RaiseException (0xABCD1234, EXCEPTION_NONCONTINUABLE, 0, NULL); UNREACHABLE_CODE (); hr = S_OK; End: return SUCCEEDED(hr) ? 0 : (int)hr; }
/*-------------------------------------------------------------------*/ static void printer_execute_ccw (DEVBLK *dev, BYTE code, BYTE flags, BYTE chained, U32 count, BYTE prevcode, int ccwseq, BYTE *iobuf, BYTE *more, BYTE *unitstat, U32 *residual) { int rc = 0; /* Return code */ U32 i; /* Loop counter */ U32 num; /* Number of bytes to move */ char *eor; /* -> end of record string */ char *nls = "\n\n\n"; /* -> new lines */ BYTE c; /* Print character */ char hex[3]; /* for hex conversion */ char wbuf[150]; /* Reset flags at start of CCW chain */ if (chained == 0) { dev->diaggate = 0; } /* Open the device file if necessary */ if (dev->fd < 0 && !IS_CCW_SENSE(code)) rc = open_printer (dev); else { /* If printer stopped, return intervention required */ if (dev->stopdev && !IS_CCW_SENSE(code)) rc = -1; else rc = 0; } if (rc < 0) { /* Set unit check with intervention required */ dev->sense[0] = SENSE_IR; *unitstat = CSW_UC; return; } /* Process depending on CCW opcode */ switch (code) { case 0x01: /* Write No Space */ case 0x09: /* Write and Space 1 Line */ case 0x11: /* Write and Space 2 Lines */ case 0x19: /* Write and Space 3 Lines */ case 0x89: /* Write and Skip to Channel 1 */ case 0x91: /* Write and Skip to Channel 2 */ case 0x99: /* Write and Skip to Channel 3 */ case 0xA1: /* Write and Skip to Channel 4 */ case 0xA9: /* Write and Skip to Channel 5 */ case 0xB1: /* Write and Skip to Channel 6 */ case 0xB9: /* Write and Skip to Channel 7 */ case 0xC1: /* Write and Skip to Channel 8 */ case 0xC9: /* Write and Skip to Channel 9 */ case 0xD1: /* Write and Skip to Channel 10 */ case 0xD9: /* Write and Skip to Channel 11 */ case 0xE1: /* Write and Skip to Channel 12 */ if (dev->rawcc) { sprintf(hex,"%02x",code); write_buffer(dev, hex, 2, unitstat); if (*unitstat != 0) return; WRITE_LINE(); write_buffer(dev, "\n", 1, unitstat); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } if ( dev->browse && dev->ccpend && ((chained & CCW_FLAGS_CD) == 0) ) { dev->ccpend = 0; /* dev->currline++; */ write_buffer(dev, "\n", 1, unitstat); if (*unitstat != 0) return; } WRITE_LINE(); if ((flags & CCW_FLAGS_CD) == 0) { if ( code <= 0x80 ) /* line control */ { coun = code / 8; if ( coun == 0 ) { dev->chskip = 1; if ( dev->browse ) { dev->ccpend = 1; *unitstat = 0; } else write_buffer(dev, "\r", 1, unitstat); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } dev->ccpend = 0; dev->currline += coun; write_buffer(dev, nls, coun, unitstat); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } else /*code > 0x80*/ /* chan control */ { /* if ( dev->browse ) { dev->currline++; write_buffer(dev, "\n", 1, unitstat); if (*unitstat != 0) return; } */ chan = ( code - 128 ) / 8; if ( chan == 1 ) { write_buffer(dev, "\r", 1, unitstat); if (*unitstat != 0) return; } SKIP_TO_CHAN(); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } } *unitstat = CSW_CE | CSW_DE; return; case 0x03: /* No Operation */ *unitstat = CSW_CE | CSW_DE; break; case 0x0B: /* Space 1 Line */ case 0x13: /* Space 2 Lines */ case 0x1B: /* Space 3 Lines */ case 0x8B: /* Skip to Channel 1 */ case 0x93: /* Skip to Channel 2 */ case 0x9B: /* Skip to Channel 3 */ case 0xA3: /* Skip to Channel 4 */ case 0xAB: /* Skip to Channel 5 */ case 0xB3: /* Skip to Channel 6 */ case 0xBB: /* Skip to Channel 7 */ case 0xC3: /* Skip to Channel 8 */ case 0xCB: /* Skip to Channel 9 */ case 0xD3: /* Skip to Channel 10 */ case 0xDB: /* Skip to Channel 11 */ case 0xE3: /* Skip to Channel 12 */ if (dev->rawcc) { sprintf(hex,"%02x",code); write_buffer(dev, hex, 2, unitstat); if (*unitstat != 0) return; eor = (dev->crlf) ? "\r\n" : "\n"; write_buffer(dev, eor, (int)strlen(eor), unitstat); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } if ( code <= 0x80 ) /* line control */ { coun = code / 8; dev->ccpend = 0; dev->currline += coun; write_buffer(dev, nls, coun, unitstat); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } else /*code > 0x80*/ /* chan control */ { /* if ( dev->browse && dev->ccpend) { coun = 1; dev->ccpend = 0; dev->currline += coun; write_buffer(dev, nls, coun, unitstat); if (*unitstat != 0) return; } */ chan = ( code - 128 ) / 8; SKIP_TO_CHAN(); if (*unitstat == 0) *unitstat = CSW_CE | CSW_DE; return; } UNREACHABLE_CODE(); case 0x63: /*---------------------------------------------------------------*/ /* LOAD FORMS CONTROL BUFFER */ /*---------------------------------------------------------------*/ if (dev->rawcc) { sprintf(hex,"%02x",code); write_buffer(dev, hex, 2, unitstat); if (*unitstat != 0) return; for (i = 0; i < count; i++) { sprintf(hex,"%02x",iobuf[i]); dev->buf[i*2] = hex[0]; dev->buf[i*2+1] = hex[1]; } /* end for(i) */ write_buffer(dev, (char *)dev->buf, i*2, unitstat); if (*unitstat != 0) return; eor = (dev->crlf) ? "\r\n" : "\n"; write_buffer(dev, eor, (int)strlen(eor), unitstat); if (*unitstat != 0) return; } else { U32 i = 0; int j = 1; int more = 1; for (i = 0; i <= FCBSIZE; i++) dev->fcb[i] = 0; dev->lpi = 6; dev->index = 0; i = 0; if (iobuf[0] & 0xc0) { /* First byte is a print position index */ if ((iobuf[0] & 0xc0) == 0x80) /* Indexing right */ dev->index = iobuf[0] & 0x1f; else /* Indexing left */ dev->index = - (iobuf[0] & 0x1f); i = 1; } for (; i < count && j <= FCBSIZE && more; i++, j++) { dev->fcb[i] = iobuf[i] & 0x0f; if (dev->fcb[j] > 12) { *residual = count - i; *unitstat = CSW_CE | CSW_DE | CSW_UC; dev->sense[0] = SENSE_CC; return; } if (iobuf[i] & 0x10) { /* Flag bit is on */ if (j == 1) /* Flag bit in first byte means eight lines per inch */ dev->lpi = 8; else more = 0; } } if (more) { /* No flag in last byte or too many bytes */ *residual = count - i; *unitstat = CSW_CE | CSW_DE | CSW_UC; dev->sense[0] = SENSE_CC; return; } *residual = count - i; dev->lpp = j - 1; fcb_dump(dev, wbuf, 150); WRMSG(HHC02210, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, wbuf ); } /* Return normal status */ *residual = 0; *unitstat = CSW_CE | CSW_DE; break; case 0x06: /*---------------------------------------------------------------*/ /* DIAGNOSTIC CHECK READ */ /*---------------------------------------------------------------*/ /* If not 1403, reject if not preceded by DIAGNOSTIC GATE */ if (dev->devtype != 0x1403 && dev->diaggate == 0) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Return normal status */ *unitstat = CSW_CE | CSW_DE; break; case 0x07: /*---------------------------------------------------------------*/ /* DIAGNOSTIC GATE */ /*---------------------------------------------------------------*/ /* Command reject if 1403, or if chained to another CCW except a no-operation at the start of the CCW chain */ if (dev->devtype == 0x1403 || ccwseq > 1 || (chained && prevcode != 0x03)) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Set diagnostic gate flag */ dev->diaggate = 1; /* Return normal status */ *unitstat = CSW_CE | CSW_DE; break; case 0x0A: /*---------------------------------------------------------------*/ /* DIAGNOSTIC READ UCS BUFFER */ /*---------------------------------------------------------------*/ /* Reject if 1403 or not preceded by DIAGNOSTIC GATE */ if (dev->devtype == 0x1403 || dev->diaggate == 0) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Return normal status */ *unitstat = CSW_CE | CSW_DE; break; case 0x12: /*---------------------------------------------------------------*/ /* DIAGNOSTIC READ fcb */ /*---------------------------------------------------------------*/ /* Reject if 1403 or not preceded by DIAGNOSTIC GATE */ if (dev->devtype == 0x1403 || dev->diaggate == 0) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Return normal status */ *unitstat = CSW_CE | CSW_DE; break; case 0x23: /*---------------------------------------------------------------*/ /* UNFOLD */ /*---------------------------------------------------------------*/ dev->fold = 0; *unitstat = CSW_CE | CSW_DE; break; case 0x43: /*---------------------------------------------------------------*/ /* FOLD */ /*---------------------------------------------------------------*/ dev->fold = 1; *unitstat = CSW_CE | CSW_DE; break; case 0x73: /*---------------------------------------------------------------*/ /* BLOCK DATA CHECK */ /*---------------------------------------------------------------*/ /* *residual = 0; */ *unitstat = CSW_CE | CSW_DE; break; case 0x7B: /*---------------------------------------------------------------*/ /* ALLOW DATA CHECK */ /*---------------------------------------------------------------*/ /* *residual = 0; */ *unitstat = CSW_CE | CSW_DE; break; case 0xEB: /*---------------------------------------------------------------*/ /* UCS GATE LOAD */ /*---------------------------------------------------------------*/ /* Command reject if not first command in chain */ if (chained != 0) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Return normal status */ *unitstat = CSW_CE | CSW_DE; break; case 0xF3: /*---------------------------------------------------------------*/ /* LOAD UCS BUFFER AND FOLD */ /*---------------------------------------------------------------*/ /* For 1403, command reject if not chained to UCS GATE */ /* Also allow ALLOW DATA CHECK to get TSS/370 working */ /* -- JRM 11/28/2007 */ if (dev->devtype == 0x1403 && ((prevcode != 0xEB) && (prevcode != 0x7B))) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Set fold indicator and return normal status */ dev->fold = 1; dev->chskip = 1; /* *residual = 0; */ *unitstat = CSW_CE | CSW_DE; break; case 0xFB: /*---------------------------------------------------------------*/ /* LOAD UCS BUFFER (NO FOLD) */ /*---------------------------------------------------------------*/ /* For 1403, command reject if not chained to UCS GATE */ if (dev->devtype == 0x1403 && prevcode != 0xEB) { dev->sense[0] = SENSE_CR; *unitstat = CSW_CE | CSW_DE | CSW_UC; break; } /* Reset fold indicator and return normal status */ dev->fold = 0; dev->chskip = 1; /* *residual = 0; */ *unitstat = CSW_CE | CSW_DE; break; case 0x04: /*---------------------------------------------------------------*/ /* SENSE */ /*---------------------------------------------------------------*/ /* Calculate residual byte count */ num = (count < dev->numsense) ? count : dev->numsense; *residual = count - num; if (count < dev->numsense) *more = 1; /* Copy device sense bytes to channel I/O buffer */ memcpy (iobuf, dev->sense, num); /* Clear the device sense bytes */ memset (dev->sense, 0, sizeof(dev->sense)); /* Return unit status */ *unitstat = CSW_CE | CSW_DE; break; case 0xE4: /*---------------------------------------------------------------*/ /* SENSE ID */ /*---------------------------------------------------------------*/ /* SENSE ID is only supported if LEGACYSENSEID is ON; * otherwise, fall through to invalid operation. */ if (sysblk.legacysenseid) { /* Calculate residual byte count */ num = (count < dev->numdevid) ? count : dev->numdevid; *residual = count - num; if (count < dev->numdevid) *more = 1; /* Copy device identifier bytes to channel I/O buffer */ memcpy (iobuf, dev->devid, num); /* Return unit status */ *unitstat = CSW_CE | CSW_DE; break; } default: /*---------------------------------------------------------------*/ /* INVALID OPERATION */ /*---------------------------------------------------------------*/ /* Set command reject sense byte, and unit check status */ dev->sense[0] = SENSE_CR; *unitstat = CSW_UC; } /* end switch(code) */ } /* end function printer_execute_ccw */
/* || Standard main */ int main( int argc, char *argv[] ) { char *pgm; /* less any extension (.ext) */ FILE *outf; int rc; int i; char pathname[MAX_PATH]; INITIALIZE_UTILITY( UTILITY_NAME, "Extract Files from AWS, HET or FAKETAPE", &pgm ); /* || Process option switches */ while( TRUE ) { rc = getopt( argc, argv, "abhnsu" ); if( rc == -1 ) { break; } switch( rc ) { case 'a': opts.flags |= O_ASCII; set_codepage(NULL); break; case 'h': usage( pgm ); exit( 1 ); UNREACHABLE_CODE(); case 'n': opts.flags |= O_NL; break; case 's': opts.flags |= O_STRIP; break; case 'u': opts.flags |= O_UNBLOCK; break; default: usage( pgm ); exit( 1 ); UNREACHABLE_CODE(); } } /* || Calc number of non-switch arguments */ argc -= optind; /* || We must have at least the first 3 parms */ if(argc < 3) { if ( argc > 1 ) // "Invalid number of arguments" FWRMSG( stderr, HHC02446, "E" ); usage( pgm ); exit( 1 ); } hostpath( pathname, argv[ optind ], sizeof(pathname) ); opts.ifile = strdup( pathname ); if ( ( rc = (int)strlen( opts.ifile ) ) > 4 && ( rc = strcasecmp( &opts.ifile[rc-4], ".fkt" ) ) == 0 ) { opts.faketape = TRUE; } hostpath( pathname, argv[ optind + 1 ], sizeof(pathname) ); opts.ofile = strdup( pathname ); opts.fileno = atoi( argv[ optind + 2 ] ); if( opts.fileno == 0 || opts.fileno > 9999 ) { char msgbuf[20]; MSGBUF( msgbuf, "%d", opts.fileno ); // "Invalid argument %s%s" FWRMSG( stderr, HHC02205, "S", msgbuf, "; file number must be within the range of 1 to 9999" ); exit( 1 ); } /* || If NL tape, then we require the DCB attributes */ if( opts.flags & O_NL ) { if( argc != 6 ) { // "DCB attributes required for NL tape" FWRMSG( stderr, HHC02750, "S" ); exit( 1 ); } } /* || If specified, get the DCB attributes */ if( argc > 3 ) { /* || Must have only three */ if( argc != 6 ) { usage( pgm ); exit( 1 ); } /* || Lookup the specified RECFM in our table */ opts.recfm = 0; for( i = 0 ; i < (int)VALFMCNT ; i++ ) { if( strcasecmp( argv[ optind + 3 ], valfm[ i ].recfm ) == 0 ) { opts.recfm = valfm[ i ].fmt; break; } } /* || If we didn't find a match, show the user what the valid ones are */ if( opts.recfm == 0) { char msgbuf[512] = ""; char msgbuf2[64] = ""; char msgbuf3[16] = ""; char msgbuf4[128] = ""; /* || Dump out the valid RECFMs */ // "Valid record formats are:" MSGBUF( msgbuf, MSG( HHC02751, "I" ) ); for( i = 0 ; i < (int)VALFMCNT ; i++ ) { MSGBUF( msgbuf3, " %-4.4s", valfm[ i ].recfm ); if( ( ( i + 1 ) % 3 ) == 0 ) { strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) ); // "%s" MSGBUF( msgbuf4, MSG( HHC02752, "I", msgbuf2 ) ); strlcat( msgbuf, msgbuf4, sizeof(msgbuf) ); msgbuf2[0] = 0; } else { strlcat( msgbuf2, msgbuf3, sizeof(msgbuf2) ); } } printf( "%s", msgbuf ); exit( 1 ); } /* || Get the record length */ opts.lrecl = atoi( argv[ optind + 4 ] ); /* || Get and validate the blksize */ opts.blksize = atoi( argv[ optind + 5 ] ); if( opts.blksize == 0 ) { // "Invalid argument %s%s" FWRMSG( stderr, HHC02205, "S", "0", "; block size can't be zero" ); exit( 1 ); } } /* || Open the tape file */ if ( opts.faketape ) rc = fet_open( &opts.fetb, opts.ifile, FETOPEN_READONLY ); else rc = het_open( &opts.hetb, opts.ifile, HETOPEN_READONLY ); if( rc >= 0 ) { /* || Get memory for the tape buffer */ blkptr = malloc( HETMAX_BLOCKSIZE ); if( blkptr != NULL ) { /* || Open the output file */ outf = fopen( opts.ofile, "wb" ); if( outf != NULL ) { /* || Go extract the file from the tape */ rc = getfile( outf ); /* || Close the output file */ fclose( outf ); } /* || Free the buffer memory */ free( blkptr ); } } else { // "Error in function %s: %s" if ( opts.faketape ) FWRMSG( stderr, HHC00075, "E", "fet_open()", fet_error( rc ) ); else FWRMSG( stderr, HHC00075, "E", "het_open()", het_error( rc ) ); } /* || Close the tape file */ if ( opts.faketape ) fet_close( &opts.fetb ); else het_close( &opts.hetb ); return 0; }
DWORD CBaseSplitterFilter::ThreadProc() { if (m_pSyncReader) { m_pSyncReader->SetBreakEvent(GetRequestHandle()); } if (!DemuxInit()) { for (;;) { DWORD cmd = GetRequest(); if (cmd == CMD_EXIT) { CAMThread::m_hThread = nullptr; } Reply(S_OK); if (cmd == CMD_EXIT) { return 0; } } } m_eEndFlush.Set(); m_fFlushing = false; for (DWORD cmd = DWORD_ERROR; ; cmd = GetRequest()) { if (cmd == CMD_EXIT) { m_hThread = nullptr; Reply(S_OK); return 0; } SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL); m_rtStart = m_rtNewStart; m_rtStop = m_rtNewStop; DemuxSeek(m_rtStart); if (cmd != DWORD_ERROR) { Reply(S_OK); } m_eEndFlush.Wait(); m_pActivePins.RemoveAll(); POSITION pos = m_pOutputs.GetHeadPosition(); while (pos && !m_fFlushing) { CBaseSplitterOutputPin* pPin = m_pOutputs.GetNext(pos); if (pPin->IsConnected() && pPin->IsActive()) { m_pActivePins.AddTail(pPin); pPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate); } } do { m_bDiscontinuitySent.RemoveAll(); } while (!DemuxLoop()); pos = m_pActivePins.GetHeadPosition(); while (pos && !CheckRequest(&cmd)) { m_pActivePins.GetNext(pos)->QueueEndOfStream(); } } UNREACHABLE_CODE(); // we should only exit via CMD_EXIT #pragma warning(pop) }
void secure_channel_accept( int fd, void *data ) { struct listener_info *listener_info = data; struct sockaddr_in addr; socklen_t addr_len; int accept_fd; int pid; addr_len = sizeof( struct sockaddr_in ); accept_fd = accept( fd, ( struct sockaddr * ) &addr, &addr_len ); if ( accept_fd < 0 ) { // TODO: close listener socket error( "Failed to accept from switch. :%s.", strerror( errno ) ); return; } pid = fork(); if ( pid < 0 ) { error( "Failed to fork. %s.", strerror( errno ) ); close( accept_fd ); return; } if ( pid == 0 ) { close( listener_info->listen_fd ); if ( accept_fd < ACCEPT_FD ) { dup2( accept_fd, ACCEPT_FD ); close( accept_fd ); accept_fd = ACCEPT_FD; } char **argv = make_switch_daemon_args( listener_info, &addr, accept_fd ); int in_fd = open( "/dev/null", O_RDONLY ); if ( in_fd != 0 ) { dup2( in_fd, 0 ); close( in_fd ); } int out_fd = open( "/dev/null", O_WRONLY ); if ( out_fd != 1 ) { dup2( out_fd, 1 ); close( out_fd ); } int err_fd = open( "/dev/null", O_WRONLY ); if ( err_fd != 2 ) { dup2( err_fd, 2 ); close( err_fd ); } execvp( listener_info->switch_daemon, argv ); error( "Failed to execvp: %s(%s) %s %s. %s.", argv[ 0 ], listener_info->switch_daemon, argv[ 1 ], argv[ 2 ], strerror( errno ) ); free_switch_daemon_args( argv ); UNREACHABLE_CODE(); } else { /* parent */ close( accept_fd ); } }