C++ 使用fork + exec安全应用程序产生

#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

pid_t
spawn(const char *file, char *const argv[])
{
    pid_t pid;
    int forkpipe[2];
    int fd_flags, err, ret;

    // set up a pipe for communication between forks
    ret = pipe(forkpipe);
    if (ret == -1)
        return -1;

    pid = fork();
    if (pid == -1) {
        err = errno;

        // close the write pipe
        close(forkpipe[1]);

        goto parent_exit;
    }

    if (pid == 0) {
        // forked child

        // close the read pipe
        ret = close(forkpipe[0]);
        if (ret == -1)
            goto child_err;

        // make the write end close-on-exec
        ret = fcntl(forkpipe[1], F_GETFD);
        if (ret == -1)
            goto child_err;
        fd_flags = ret | FD_CLOEXEC;
        ret = fcntl(forkpipe[1], F_SETFD, fd_flags);
        if (ret == -1)
            goto child_err;

        // try to run the app
        execvp(file, argv);
        // if we continue executing here, an error occurred

child_err:
        // send the error code through the write pipe
        err = errno;
        write(forkpipe[1], &err, sizeof(err));

        exit(1);
    }

    // parent

    // close the write pipe
    close(forkpipe[1]);

    // get the error code from the read pipe
    ret = read(forkpipe[0], &err, sizeof(err));
    if (ret == -1) {
        err = errno;
        pid = -1;
    } else if (ret == sizeof(err))
        pid = -1;
    else
        err = 0;

parent_exit:
    // close the read pipe
    close(forkpipe[0]);

    if (err)
        errno = err;

    return pid;
}

Bash 计算子目录中的文件

find . -name '.svn' -prune -or -maxdepth 2 -type d -print -exec sh -c 'find {} -name ".svn" -prune -or -print | wc -l' \;

JavaScript 修复IE中“选择下的菜单”问题

/* Son of Suckerfish Dropdowns. JS needed only for
   Internet Explorer. Documented here:
   http://www.htmldog.com/articles/suckerfish/dropdowns/*/
sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    /* Create an array of all <select> tags on the page (could be limited to 
    those within an element with a specific id -- see line above. */
    var selects = document.getElementsByTagName("select"); 
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
            for (var n=0; n<selects.length; n++) {
                /* Hides <select> tags, which appear above menu in IE */
                selects[n].className+=" hide_select";
            }
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
            for (var n=0; n<selects.length; n++) {
                /* Makes <select> tags visible again */
                selects[n].className = selects[n].className.replace(new RegExp(" hide_select\\b"), "");
            }
        }
    }
}

/* 
 * NOTE: In order for this snippet to work, you need to add the 
 * following lines (or something similar) to your CSS:
 *
 * select.hide_select {
 *     visibility: hidden;
 * }
 *
 * Using "display: none" may cause other elements to shift as the is 
 * completely removed from the flow of the document. By using
 * "visibility: hidden", the just becomes "invisible."
 */

PHP 使用条件WHERE部分进行SELECT

$selsearch =	'
SELECT 
	Uni,Prof,Bearbeiter,Jahr,Semester,ID,Thema,status
FROM 
	Habilitation 
	WHERE 1 ';
	
if ( strlen($_GET["uni"])>0 ) { $selsearch	.= ' AND Uni LIKE "'.$_GET["uni"].'%" '; }
if ( strlen($_GET["jahr"])>0 ) { $selsearch	.= ' AND jahr LIKE "'.$_GET["jahr"].'%" '; }
if ( strlen($_GET["thema"])>0 ) { $selsearch	.= ' AND Thema LIKE "%'.$_GET["thema"].'%" '; }

$selsearch .=	' ORDER BY '.$o.' LIMIT '.$posSelect.','.$perpage;

JavaScript Ajaxã??å??æ©

<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<title>Ajax Test</title>

		<script type="text/javascript" charset="utf-8">
		function sendData() {
			request = new XMLHttpRequest();
			request.onreadystatechange=handleRespons;
			request.open("GET", "sender.php", true);
			request.send(null);
		}

		function handleRespons() {
			if (request.readyState == 4) {
				if (request.status == 200) {
					var fld = document.getElementById("response");
					fld.innerHTML = request.responseText
				}
			}
		}
		</script>
	</head>

	<form action="javascript:void%200" onsubmit="sendData();return false;">
		<button type="submit">現在時刻(サーバーの)</button>
	</form>

	<div id="response" style="color: red; font-size: 40px;" ></div>
</html>

PHP C 14¾åœ¨æ™,A»ã,'出åŠ>的ΔΣ™ã,<

&lt;?php
	echo date(&quot;g:i:s a&quot;);
?&gt;

ASP ASP - Pintar str buscado

function pintar( q, str )
	Set regEx = New RegExp
	regEx.Pattern = q
	regEx.IgnoreCase = True
	regEx.Global = True
	TextosResultado = regEx.Replace(str, &quot;&lt;font style=&quot;&quot;background-color:#FAEEEF&quot;&quot;&gt;&quot;&amp; q &amp;&quot;&lt;/font&gt;&quot;)
	pintar = TextosResultado
end function

ASP ASP - Eregi Para Regex

Function eregi(ByVal str, ByVal patrn,ByVal rpl)
'EJ, para sacar tags eregi(texto,&quot;&lt;([^&gt;]+)&gt;&quot;,&quot;&quot;)
'Ej, para sacar los links eregi(texto,&quot;&lt;a([^&gt;]+)&gt;|&lt;/a&gt;&quot;,&quot;&quot;)
		 Set regEx = New RegExp
		 regEx.Pattern = patrn
		 regEx.IgnoreCase = True
		 regEx.Global = True
		 StrReplace = regEx.Replace(str,rpl)
		eregi = StrReplace
End function

Bash 什么版本的Apache?

httpd -V

PHP cakephp有奇怪的会话问题

First visit. No session, no cookies so far.

$_COOKIE: 
Array()

$_SESSION: 
Array
(
    [Config] =&gt; Array
        (
            [rand] =&gt; 2031703447
            [time] =&gt; 1166640164
            [userAgent] =&gt; 05c06381cba0c03d1fda664faf636fab
        )

)

SID: WEGNERDE=4068f91034bca9992f4e86fb555b3997

sessioncomponent Object
(
    [_log] =&gt; 
    [CakeSession] =&gt; cakesession Object
        (
            [_log] =&gt; 
            [valid] =&gt; 1
            [error] =&gt; Array
                (
                    [2] =&gt; Config doesn't exist
                    [1] =&gt; Session is valid
                )

            [_userAgent] =&gt; 05c06381cba0c03d1fda664faf636fab
            [path] =&gt; /index.php/
            [lastError] =&gt; 1
            [security] =&gt; high
            [time] =&gt; 1166638964
            [sessionTime] =&gt; 1166640164
            [host] =&gt; www.[snip].de
            [cookieLifeTime] =&gt; 0
        )

    [base] =&gt; /index.php
    [webroot] =&gt; /wegner/webroot/
    [here] =&gt; /index.php/nodes/view/18
    [params] =&gt; Array
        (
            [controller] =&gt; nodes
            [action] =&gt; view
            [pass] =&gt; Array
                (
                    [0] =&gt; 18
                )

            [form] =&gt; Array
                (
                )

            [url] =&gt; Array
                (
                    [url] =&gt; /nodes/view/18
                )

            [bare] =&gt; 0
            [webservices] =&gt; 
            [plugin] =&gt; 
        )

    [action] =&gt; view
    [data] =&gt; 
    [plugin] =&gt; 
)

DB:
select '4068f91034bca9992f4e86fb555b3997', zero results
insert row with id '4068f91034bca9992f4e86fb555b3997'

===================
Second page visit
===================

$_COOKIE:
Array
(
    [WEGNERDE] =&gt; 4068f91034bca9992f4e86fb555b3997
)

$_SESSION:
Array
(
    [Config] =&gt; Array
        (
            [rand] =&gt; 724195738
            [time] =&gt; 1166640598
            [userAgent] =&gt; 05c06381cba0c03d1fda664faf636fab
        )

)

SID: (empty)

sessioncomponent Object
(
    [_log] =&gt; 
    [CakeSession] =&gt; cakesession Object
        (
            [_log] =&gt; 
            [valid] =&gt; 1
            [error] =&gt; Array
                (
                    [2] =&gt; Config doesn't exist
                    [1] =&gt; Session is valid
                )

            [_userAgent] =&gt; 05c06381cba0c03d1fda664faf636fab
            [path] =&gt; /index.php/
            [lastError] =&gt; 1
            [security] =&gt; high
            [time] =&gt; 1166639398
            [sessionTime] =&gt; 1166640598
            [host] =&gt; www.[snip].de
            [cookieLifeTime] =&gt; 0
        )

    [base] =&gt; /index.php
    [webroot] =&gt; /wegner/webroot/
    [here] =&gt; /index.php/users/login
    [params] =&gt; Array
        (
            [controller] =&gt; users
            [action] =&gt; login
            [form] =&gt; Array
                (
                )

            [url] =&gt; Array
                (
                    [url] =&gt; /users/login
                )

            [bare] =&gt; 0
            [webservices] =&gt; 
            [plugin] =&gt; 
        )

    [action] =&gt; login
    [data] =&gt; 
    [plugin] =&gt; 
)


DB:
select id 'c2042ca664205240f5e327762e615d72', 0 results
insert new row with id = c2042ca664205240f5e327762e615d72