From owner-svn-soc-all@FreeBSD.ORG Sun Jun 23 12:53:54 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 139EFE30 for ; Sun, 23 Jun 2013 12:53:54 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id E88671BDD for ; Sun, 23 Jun 2013 12:53:53 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5NCrrxm013608 for ; Sun, 23 Jun 2013 12:53:53 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5NCrroI013605 for svn-soc-all@FreeBSD.org; Sun, 23 Jun 2013 12:53:53 GMT (envelope-from dpl@FreeBSD.org) Date: Sun, 23 Jun 2013 12:53:53 GMT Message-Id: <201306231253.r5NCrroI013605@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253376 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jun 2013 12:53:54 -0000 Author: dpl Date: Sun Jun 23 12:53:53 2013 New Revision: 253376 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253376 Log: Declare structs needed to pass fds only if needed. (Not compiliing and don't know why, investigating) Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Sun Jun 23 10:51:26 2013 (r253375) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Sun Jun 23 12:53:53 2013 (r253376) @@ -91,7 +91,7 @@ # ifdef __FreeBSD__ # include # if __FreeBSD_version >= 900041 -# define CAPSICUM +# define CAPSICUM 1 # include # include # include @@ -221,17 +221,28 @@ FILE *outputHandleJustInCase; Int32 workFactor; -#ifdef CAPSICUM +#if CAPSICUM int sv[2], len; +char buf[1]; +char cms[CMSG_SPACE(sizeof(int))]; +struct iovec iov; struct cmsghdr *cmsg; +struct msghdr msg; +buf[0] = 0; +iov.iov_base = buf; +iov.iov_len = 1; + +cmsg->cmsg_len = CMSG_LEN(sizeof (int)); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SOL_RIGHTS; -struct msghdr msg; + msg.msg_name = NULL; -msg.msg_namelen = 0; -msg.msg_iov = NULL; -msg.msg_iovlen = 0; +msg.,msg_namelen = 0; +msg.msg_iov = &iov; +msg.msg_iovlen = 1; +/* msg.msg_control = (caddr_t)cms; */ +/* msg.msg_controllen = CMSG_LEN(sizeof(int)); */ #endif static void panic ( const Char* ) NORETURN; @@ -987,7 +998,7 @@ FILE* fp; IntNative fh; fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR); -# ifdef CAPSICUM +# if CAPSICUM cap_rights_limit(fh, CAP_WRITE); # endif if (fh == -1) return NULL; @@ -1162,7 +1173,7 @@ FILE *inStr; FILE *outStr; Int32 n, i; -# ifdef CAPSICUM +# if CAPSICUM Int32 infd; pid_t forkpid; # endif @@ -1254,7 +1265,7 @@ } if ( srcMode != SM_I2O ){ -# ifdef CAPSICUM +# if CAPSICUM infd = open( inName, O_RDONLY ); cap_rights_limit(infd, CAP_READ); inStr = fdopen ( infd, "rb" ); @@ -1328,7 +1339,7 @@ fflush ( stderr ); } -# ifdef CAPSICUM +# if CAPSICUM /* Pass the limited file descriptors with a unix domain socket. */ switch( forkpid = rfork(RFPROC | RFCFDG) ) { case ( 0 ): @@ -1358,7 +1369,7 @@ deleteOutputOnInterrupt = False; -# ifdef CAPSICUM +# if CAPSICUM break; case ( -1 ): @@ -1367,7 +1378,7 @@ default: /* Send the two FDs */ - sendmsg(); + /* sendmsg(); */ wait(NULL); return; } @@ -1383,7 +1394,7 @@ FILE *inStr; FILE *outStr; Int32 n, i; -# ifdef CAPSICUM +# if CAPSICUM Int32 infd; pid_t forkpid; # endif @@ -1480,7 +1491,7 @@ } if ( srcMode != SM_I2O ){ -# ifdef CAPSICUM +# if CAPSICUM infd = open( inName, O_RDONLY ); cap_rights_limit(infd, CAP_READ); inStr = fdopen ( infd, "rb" ); @@ -2035,7 +2046,7 @@ # endif } -# ifdef CAPSICUM +# if CAPSICUM if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1 ){ fprintf ( stderr, "%s: Can't create socket: %s.\n", progName, strerror(errno) ); From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 14:36:00 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 15EB42DC for ; Mon, 24 Jun 2013 14:36:00 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id E14831B31 for ; Mon, 24 Jun 2013 14:35:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OEZx2W008275 for ; Mon, 24 Jun 2013 14:35:59 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OEZxnt008270 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 14:35:59 GMT (envelope-from ccqin@FreeBSD.org) Date: Mon, 24 Jun 2013 14:35:59 GMT Message-Id: <201306241435.r5OEZxnt008270@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253425 - soc2013/ccqin/head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 14:36:00 -0000 Author: ccqin Date: Mon Jun 24 14:35:59 2013 New Revision: 253425 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253425 Log: fork the full source tree Added: soc2013/ccqin/head/ (props changed) - copied from r253424, mirror/FreeBSD/head/ From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 14:40:09 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 43E81332 for ; Mon, 24 Jun 2013 14:40:09 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 1B6F81B61 for ; Mon, 24 Jun 2013 14:40:09 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OEe9HA037405 for ; Mon, 24 Jun 2013 14:40:09 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OEe87C037396 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 14:40:08 GMT (envelope-from ccqin@FreeBSD.org) Date: Mon, 24 Jun 2013 14:40:08 GMT Message-Id: <201306241440.r5OEe87C037396@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253426 - soc2013/ccqin/head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 14:40:09 -0000 Author: ccqin Date: Mon Jun 24 14:40:08 2013 New Revision: 253426 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253426 Log: Deleted: soc2013/ccqin/head/ From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 14:40:47 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id BF46C350 for ; Mon, 24 Jun 2013 14:40:47 +0000 (UTC) (envelope-from ccqin@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 970111B6D for ; Mon, 24 Jun 2013 14:40:47 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OEel0C058599 for ; Mon, 24 Jun 2013 14:40:47 GMT (envelope-from ccqin@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OEelQE058585 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 14:40:47 GMT (envelope-from ccqin@FreeBSD.org) Date: Mon, 24 Jun 2013 14:40:47 GMT Message-Id: <201306241440.r5OEelQE058585@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ccqin@FreeBSD.org using -f From: ccqin@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253427 - soc2013/ccqin/head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 14:40:47 -0000 Author: ccqin Date: Mon Jun 24 14:40:47 2013 New Revision: 253427 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253427 Log: Added: soc2013/ccqin/head/ (props changed) - copied from r253426, mirror/FreeBSD/head/ From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 18:40:07 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 42C8E51A for ; Mon, 24 Jun 2013 18:40:07 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 1C2851864 for ; Mon, 24 Jun 2013 18:40:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OIe7ot020605 for ; Mon, 24 Jun 2013 18:40:07 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OIe79e020597 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 18:40:07 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 18:40:07 GMT Message-Id: <201306241840.r5OIe79e020597@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253431 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 18:40:07 -0000 Author: mattbw Date: Mon Jun 24 18:40:06 2013 New Revision: 253431 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253431 Log: move dummy to backend Added: soc2013/mattbw/backend/ - copied from r253430, soc2013/mattbw/dummy/ From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 18:54:15 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 03D20A32 for ; Mon, 24 Jun 2013 18:54:15 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id DBF1C18F4 for ; Mon, 24 Jun 2013 18:54:14 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OIsEi0048977 for ; Mon, 24 Jun 2013 18:54:14 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OIsE36048975 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 18:54:14 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 24 Jun 2013 18:54:14 GMT Message-Id: <201306241854.r5OIsE36048975@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253432 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 18:54:15 -0000 Author: dpl Date: Mon Jun 24 18:54:14 2013 New Revision: 253432 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253432 Log: Added recvfds() and sendfds(). Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 18:40:06 2013 (r253431) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 18:54:14 2013 (r253432) @@ -221,28 +221,74 @@ FILE *outputHandleJustInCase; Int32 workFactor; -#if CAPSICUM -int sv[2], len; -char buf[1]; -char cms[CMSG_SPACE(sizeof(int))]; -struct iovec iov; -struct cmsghdr *cmsg; -struct msghdr msg; - -buf[0] = 0; -iov.iov_base = buf; -iov.iov_len = 1; - -cmsg->cmsg_len = CMSG_LEN(sizeof (int)); -cmsg->cmsg_level = SOL_SOCKET; -cmsg->cmsg_type = SOL_RIGHTS; - -msg.msg_name = NULL; -msg.,msg_namelen = 0; -msg.msg_iov = &iov; -msg.msg_iovlen = 1; -/* msg.msg_control = (caddr_t)cms; */ -/* msg.msg_controllen = CMSG_LEN(sizeof(int)); */ +#if CAPSICUM == 1 +int sv[2], fds[2], len; +int sendfds(int, int*); +int recvfds(int); + +int +sendfds(int s, int fd[2]) +{ + char buf[1]; + struct iovec iov; + struct msghdr msg; + struct cmsghdr *cmsg; + char cms[CMSG_SPACE(2*sizeof(int))]; + + buf[0] = 0; + iov.iov_base = buf; + iov.iov_len = 1; + + memset(&msg, 0, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (caddr_t)cms; + msg.msg_controllen = CMSG_LEN(2*sizeof(int)); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + memmove(CMSG_DATA(cmsg), &fd, 2*sizeof(int)); + + if((sendmsg(s, &msg, 0)) != (int)iov.iov_len) + return -1; + return 0; +} + +int +recvfds(int s) +{ + int n; + int fds[2]; + char buf[1]; + struct iovec iov; + struct msghdr msg; + struct cmsghdr *cmsg; + char cms[CMSG_SPACE(2*sizeof(int))]; + + iov.iov_base = buf; + iov.iov_len = 1; + + memset(&msg, 0, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + msg.msg_control = (caddr_t)cms; + msg.msg_controllen = sizeof cms; + + if((n = recvmsg(s, &msg, 0)) < 0) + return -1; + if(n == 0){ + fprintf ( stderr, + "\n%s: recvfds: Unexpected EOF.\n", + progName); + return -1; + } + cmsg = CMSG_FIRSTHDR(&msg); + memmove(&fds, CMSG_DATA(cmsg), sizeof(int)); + return fds; +} #endif static void panic ( const Char* ) NORETURN; @@ -1377,8 +1423,7 @@ exit(1); default: - /* Send the two FDs */ - /* sendmsg(); */ + wait(NULL); return; } @@ -1394,10 +1439,6 @@ FILE *inStr; FILE *outStr; Int32 n, i; -# if CAPSICUM - Int32 infd; - pid_t forkpid; -# endif Bool magicNumberOK; Bool cantGuess; struct MY_STAT statBuf; @@ -1491,13 +1532,13 @@ } if ( srcMode != SM_I2O ){ -# if CAPSICUM - infd = open( inName, O_RDONLY ); - cap_rights_limit(infd, CAP_READ); - inStr = fdopen ( infd, "rb" ); -# else +/*# if CAPSICUM*/ + /*infd = open( inName, O_RDONLY );*/ + /*cap_rights_limit(infd, CAP_READ);*/ + /*inStr = fdopen ( infd, "rb" );*/ +/*# else*/ inStr = fopen ( inName, "rb" ); -# endif +/*# endif*/ } switch ( srcMode ) { From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 19:24:46 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4A733808 for ; Mon, 24 Jun 2013 19:24:46 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 3BFB71A52 for ; Mon, 24 Jun 2013 19:24:46 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OJOkQG013624 for ; Mon, 24 Jun 2013 19:24:46 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OJOkPS013621 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 19:24:46 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 19:24:46 GMT Message-Id: <201306241924.r5OJOkPS013621@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253438 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 19:24:46 -0000 Author: mattbw Date: Mon Jun 24 19:24:45 2013 New Revision: 253438 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253438 Log: vanity and minor formatting changes Modified: soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 18:41:28 2013 (r253437) +++ soc2013/mattbw/backend/get-details.c Mon Jun 24 19:24:45 2013 (r253438) @@ -145,8 +145,7 @@ success = FALSE; it = pkgdb_query(db, name, MATCH_EXACT); if (it) - success = get_details_check_matches( - it, + success = get_details_check_matches(it, name, version, arch, @@ -170,8 +169,7 @@ success = FALSE; it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); if (it) - success = get_details_check_matches( - it, + success = get_details_check_matches(it, name, version, arch, Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 18:41:28 2013 (r253437) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 19:24:45 2013 (r253438) @@ -1491,7 +1491,7 @@ gchar * pk_backend_get_description(PkBackend * backend) { - return g_strdup("Dummy"); + return g_strdup("pkgng"); } /** @@ -1500,5 +1500,5 @@ gchar * pk_backend_get_author(PkBackend * backend) { - return g_strdup("Richard Hughes "); + return g_strdup("Matt Windsor "); } From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 19:45:47 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 055BC93 for ; Mon, 24 Jun 2013 19:45:47 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id DBBE81BF0 for ; Mon, 24 Jun 2013 19:45:46 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OJjkrO044602 for ; Mon, 24 Jun 2013 19:45:46 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OJjkTu044595 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 19:45:46 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 19:45:46 GMT Message-Id: <201306241945.r5OJjkTu044595@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253439 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 19:45:47 -0000 Author: mattbw Date: Mon Jun 24 19:45:46 2013 New Revision: 253439 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253439 Log: cleanup, separate database opener to db.[ch], re-indent Added: soc2013/mattbw/backend/db.c soc2013/mattbw/backend/db.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/get-details.h soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Mon Jun 24 19:24:45 2013 (r253438) +++ soc2013/mattbw/backend/Makefile Mon Jun 24 19:45:46 2013 (r253439) @@ -2,7 +2,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c get-details.c groups.c +SRCS= pk-backend-pkgng.c get-details.c groups.c db.c USE_PK_PKGCONF= 0 Added: soc2013/mattbw/backend/db.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/db.c Mon Jun 24 19:45:46 2013 (r253439) @@ -0,0 +1,57 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "pk-backend.h" +#include "pkg.h" + +/* + * Opens a pkgdb ready for remote operations. This will always return TRUE if + * and only if a database ready for use is now pointed to by *db, and FALSE + * if and only if there isn't. + * + * This will also emit PackageKit errors if it fails. + * + * This must be called during the lifetime of "backend", eg after + * "pk_backend_initialize" and before "pk_backend_destroy". + */ +gboolean +open_remote_db(struct pkgdb **db, PkBackend *backend) +{ + gboolean success; + int open_return; + + /* TODO: pkgdb_access for pkg1.1 */ + success = FALSE; + open_return = pkgdb_open(db, PKGDB_REMOTE); + if (open_return != EPKG_OK) + pk_backend_error_code(backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "pkgdb_open returned an error"); + else if (*db == NULL) + pk_backend_error_code(backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "pkgdb_open gave us a null pointer"); + else + success = TRUE; + + return success; +} Added: soc2013/mattbw/backend/db.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/db.h Mon Jun 24 19:45:46 2013 (r253439) @@ -0,0 +1,31 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_DB_H_ +#define _PKGNG_BACKEND_DB_H_ + +#include /* gboolean */ +#include "pk-backend.h" /* PkBackend */ +#include "pkg.h" /* struct pkgdb */ + +gboolean open_remote_db(struct pkgdb **db, PkBackend *backend); + +#endif /* !_PKGNG_BACKEND_DETAILS_H_ */ Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 19:24:45 2013 (r253438) +++ soc2013/mattbw/backend/get-details.c Mon Jun 24 19:45:46 2013 (r253439) @@ -26,6 +26,17 @@ #include "groups.h" +static gboolean +get_local_details(gchar *name, + gchar *version, + gchar *arch, + PkBackend *backend, + struct pkgdb *db); +static gboolean +get_details_for(gchar *package_id, + PkBackend *backend, + struct pkgdb *db); + /* * Checks two strings with strcmp and emits TRUE if they match. If either * string is NULL, emit TRUE as well (this is so that missing PackageID @@ -132,7 +143,7 @@ } /* Looks the split PackageID up in the local database. */ -gboolean +static gboolean get_local_details(gchar *name, gchar *version, gchar *arch, @@ -247,3 +258,34 @@ return success; } + +/* + * The thread that performs a GetDetails operation. Should be invoked by the + * pk_backend_get_details hook. + */ +gboolean +get_details_thread(PkBackend *backend) +{ + gboolean no_error_yet; + gchar **package_ids; + guint len; + guint i; + struct pkgdb *db; + + + package_ids = pk_backend_get_strv(backend, "package_ids"); + len = g_strv_length(package_ids); + + db = NULL; + no_error_yet = open_remote_db(&db, backend); + + pk_backend_set_percentage(backend, 0); + for (i = 0; i < len && no_error_yet; i++) { + no_error_yet = get_details_for(package_ids[0], backend, db); + pk_backend_set_percentage(backend, ((i * 100) / len)); + } + pkgdb_close(db); + + pk_backend_finished(backend); + return no_error_yet; +} Modified: soc2013/mattbw/backend/get-details.h ============================================================================== --- soc2013/mattbw/backend/get-details.h Mon Jun 24 19:24:45 2013 (r253438) +++ soc2013/mattbw/backend/get-details.h Mon Jun 24 19:45:46 2013 (r253439) @@ -18,9 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef _GET_DETAILS_H_ -#define _GET_DETAILS_H_ +#ifndef _PKGNG_BACKEND_GET_DETAILS_H_ +#define _PKGNG_BACKEND_GET_DETAILS_H_ -gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); +#include /* gboolean */ +#include "pk-backend.h" /* PkBackend */ -#endif /* !_GET_DETAILS_H_ */ +gboolean get_details_thread(PkBackend *backend); + +#endif /* !_PKGNG_BACKEND_GET_DETAILS_H_ */ Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 19:24:45 2013 (r253438) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 19:45:46 2013 (r253439) @@ -57,55 +57,34 @@ static guint _socket_listen_id = 0; struct pkgng_private { - struct pkgdb *db; + struct pkgdb *db; }; static struct pkgng_private priv; -gboolean -open_remote_db(struct pkgdb **db, PkBackend *backend) -{ - gboolean success; - int open_return; - - success = FALSE; - open_return = pkgdb_open(db, PKGDB_REMOTE); - if (open_return != EPKG_OK) - pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "pkgdb_open returned an error"); - else if (*db == NULL) - pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "pkgdb_open gave us a null pointer"); - else - success = TRUE; - - return success; -} /** * pk_backend_initialize: */ void -pk_backend_initialize(PkBackend * backend) +pk_backend_initialize(PkBackend *backend) { - int err; + int err; _progress_percentage = 0; err = pkg_init(NULL); if (err) pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "could not initialise pkg"); + PK_ERROR_ENUM_INTERNAL_ERROR, + "could not initialise pkg"); } /** * pk_backend_destroy: */ void -pk_backend_destroy(PkBackend * backend) +pk_backend_destroy(PkBackend *backend) { pkg_shutdown(); } @@ -114,7 +93,7 @@ * pk_backend_get_groups: */ PkBitfield -pk_backend_get_groups(PkBackend * backend) +pk_backend_get_groups(PkBackend *backend) { return pk_bitfield_from_enums(PK_GROUP_ENUM_ACCESSIBILITY, PK_GROUP_ENUM_GAMES, @@ -126,7 +105,7 @@ * pk_backend_get_filters: */ PkBitfield -pk_backend_get_filters(PkBackend * backend) +pk_backend_get_filters(PkBackend *backend) { return pk_bitfield_from_enums(PK_FILTER_ENUM_GUI, PK_FILTER_ENUM_INSTALLED, @@ -138,7 +117,7 @@ * pk_backend_get_mime_types: */ gchar * -pk_backend_get_mime_types(PkBackend * backend) +pk_backend_get_mime_types(PkBackend *backend) { return g_strdup("application/x-rpm;application/x-deb"); } @@ -146,10 +125,10 @@ /** * pk_backend_cancel_timeout: */ -static gboolean +static gboolean pk_backend_cancel_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; /* we can now cancel again */ _signal_timeout = 0; @@ -165,7 +144,7 @@ * pk_backend_cancel: */ void -pk_backend_cancel(PkBackend * backend) +pk_backend_cancel(PkBackend *backend) { /* cancel the timeout */ if (_signal_timeout != 0) { @@ -180,7 +159,7 @@ * pk_backend_get_depends: */ void -pk_backend_get_depends(PkBackend * backend, PkBitfield filters, gchar ** package_ids, gboolean recursive) +pk_backend_get_depends(PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); @@ -196,51 +175,26 @@ pk_backend_finished(backend); } -gboolean -backend_get_details_thread(PkBackend *backend) -{ - gboolean no_error_yet; - gchar **package_ids; - guint len; - guint i; - struct pkgdb *db; - - - package_ids = pk_backend_get_strv(backend, "package_ids"); - len = g_strv_length(package_ids); - - db = NULL; - no_error_yet = open_remote_db(&db, backend); - pk_backend_set_percentage(backend, 0); - for (i = 0; i < len && no_error_yet; i++) { - no_error_yet = get_details_for(package_ids[0], backend, db); - pk_backend_set_percentage(backend, ((i * 100) / len)); - } - pkgdb_close(db); - pk_backend_finished(backend); - return no_error_yet; -} - - -/** - * pk_backend_get_details: +/* + * Spawns a thread to get the details of the package IDs requested. The + * thread code proper is in "get-details.c". */ void -pk_backend_get_details(PkBackend * backend, gchar ** package_ids) +pk_backend_get_details(PkBackend *backend, gchar **package_ids) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); - pk_backend_thread_create(backend, backend_get_details_thread); + pk_backend_thread_create(backend, get_details_thread); } /** * pk_backend_get_distro_upgrades: */ void -pk_backend_get_distro_upgrades(PkBackend * backend) +pk_backend_get_distro_upgrades(PkBackend *backend) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); if (!_use_distro_upgrade) @@ -257,7 +211,7 @@ * pk_backend_get_files: */ void -pk_backend_get_files(PkBackend * backend, gchar ** package_ids) +pk_backend_get_files(PkBackend *backend, gchar **package_ids) { guint i; guint len; @@ -284,7 +238,7 @@ * pk_backend_get_requires: */ void -pk_backend_get_requires(PkBackend * backend, PkBitfield filters, gchar ** package_ids, gboolean recursive) +pk_backend_get_requires(PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_package(backend, PK_INFO_ENUM_INSTALLED, @@ -297,13 +251,13 @@ /** * pk_backend_get_update_detail_timeout: **/ -static gboolean +static gboolean pk_backend_get_update_detail_timeout(gpointer data) { guint i; guint len; const gchar *package_id; - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; const gchar *changelog; /* dummy */ @@ -384,7 +338,7 @@ * pk_backend_get_update_detail: */ void -pk_backend_get_update_detail(PkBackend * backend, gchar ** package_ids) +pk_backend_get_update_detail(PkBackend *backend, gchar **package_ids) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); _package_ids = package_ids; @@ -394,10 +348,10 @@ /** * pk_backend_get_updates_timeout: **/ -static gboolean +static gboolean pk_backend_get_updates_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_use_blocked) { if (!_updated_powertop && !_updated_kernel && !_updated_gtkhtml) { @@ -430,7 +384,7 @@ * pk_backend_get_updates: */ void -pk_backend_get_updates(PkBackend * backend, PkBitfield filters) +pk_backend_get_updates(PkBackend *backend, PkBitfield filters) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); @@ -443,10 +397,10 @@ _signal_timeout = g_timeout_add(1000, pk_backend_get_updates_timeout, backend); } -static gboolean +static gboolean pk_backend_install_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; guint sub_percent; if (_progress_percentage == 100) { @@ -470,7 +424,7 @@ pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); } if (_progress_percentage > 30 && _progress_percentage < 50) { - sub_percent = ((gfloat) (_progress_percentage - 30.0f) / 20.0f) * 100.0f; + sub_percent = ((gfloat) (_progress_percentage - 30.0) / 20.0) * 100.0; pk_backend_set_sub_percentage(backend, sub_percent); } else { pk_backend_set_sub_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); @@ -484,7 +438,7 @@ * pk_backend_install_packages: */ void -pk_backend_install_packages(PkBackend * backend, gboolean only_trusted, gchar ** package_ids) +pk_backend_install_packages(PkBackend *backend, gboolean only_trusted, gchar **package_ids) { const gchar *license_agreement; const gchar *eula_id; @@ -560,8 +514,8 @@ * pk_backend_install_signature: */ void -pk_backend_install_signature(PkBackend * backend, PkSigTypeEnum type, - const gchar * key_id, const gchar * package_id) +pk_backend_install_signature(PkBackend *backend, PkSigTypeEnum type, + const gchar *key_id, const gchar *package_id) { pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); if (type == PK_SIGTYPE_ENUM_GPG && @@ -580,10 +534,10 @@ /** * pk_backend_refresh_cache_timeout: */ -static gboolean +static gboolean pk_backend_install_files_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; pk_backend_finished(backend); return FALSE; } @@ -592,7 +546,7 @@ * pk_backend_install_files: */ void -pk_backend_install_files(PkBackend * backend, gboolean only_trusted, gchar ** full_paths) +pk_backend_install_files(PkBackend *backend, gboolean only_trusted, gchar **full_paths) { pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); pk_backend_set_percentage(backend, 101); @@ -602,10 +556,10 @@ /** * pk_backend_refresh_cache_timeout: */ -static gboolean +static gboolean pk_backend_refresh_cache_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_progress_percentage == 100) { pk_backend_finished(backend); return FALSE; @@ -621,7 +575,7 @@ * pk_backend_refresh_cache: */ void -pk_backend_refresh_cache(PkBackend * backend, gboolean force) +pk_backend_refresh_cache(PkBackend *backend, gboolean force) { _progress_percentage = 0; @@ -638,10 +592,10 @@ /** * pk_backend_resolve_timeout: */ -static gboolean +static gboolean pk_backend_resolve_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; guint i; guint len; gchar **packages = _package_ids; @@ -683,7 +637,7 @@ * pk_backend_resolve: */ void -pk_backend_resolve(PkBackend * backend, PkBitfield filters, gchar ** packages) +pk_backend_resolve(PkBackend *backend, PkBitfield filters, gchar **packages) { _filters = filters; _package_ids = packages; @@ -693,10 +647,10 @@ /** * pk_backend_rollback_timeout: */ -static gboolean +static gboolean pk_backend_rollback_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_progress_percentage == 0) { _updated_gtkhtml = FALSE; _updated_kernel = FALSE; @@ -719,7 +673,7 @@ * pk_backend_rollback: */ void -pk_backend_rollback(PkBackend * backend, const gchar * transaction_id) +pk_backend_rollback(PkBackend *backend, const gchar *transaction_id) { /* allow testing error condition */ if (g_strcmp0(transaction_id, "/397_eeecadad_data") == 0) { @@ -738,7 +692,7 @@ * pk_backend_remove_packages: */ void -pk_backend_remove_packages(PkBackend * backend, gchar ** package_ids, gboolean allow_deps, gboolean autoremove) +pk_backend_remove_packages(PkBackend *backend, gchar **package_ids, gboolean allow_deps, gboolean autoremove) { pk_backend_set_status(backend, PK_STATUS_ENUM_REMOVE); pk_backend_error_code(backend, PK_ERROR_ENUM_NO_NETWORK, "No network connection available"); @@ -749,7 +703,7 @@ * pk_backend_search_details: */ void -pk_backend_search_details(PkBackend * backend, PkBitfield filters, gchar ** values) +pk_backend_search_details(PkBackend *backend, PkBitfield filters, gchar **values) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); @@ -763,7 +717,7 @@ * pk_backend_search_files: */ void -pk_backend_search_files(PkBackend * backend, PkBitfield filters, gchar ** values) +pk_backend_search_files(PkBackend *backend, PkBitfield filters, gchar **values) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); @@ -782,7 +736,7 @@ * pk_backend_search_groups: */ void -pk_backend_search_groups(PkBackend * backend, PkBitfield filters, gchar ** values) +pk_backend_search_groups(PkBackend *backend, PkBitfield filters, gchar **values) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); @@ -798,11 +752,11 @@ /** * pk_backend_search_name_timeout: **/ -static gboolean +static gboolean pk_backend_search_name_timeout(gpointer data) { gchar *locale; - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; locale = pk_backend_get_locale(backend); g_debug("locale is %s", locale); @@ -832,7 +786,7 @@ * pk_backend_search_names: */ void -pk_backend_search_names(PkBackend * backend, PkBitfield filters, gchar ** values) +pk_backend_search_names(PkBackend *backend, PkBitfield filters, gchar **values) { pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_set_allow_cancel(backend, TRUE); @@ -843,10 +797,10 @@ /** * pk_backend_update_packages_download_timeout: **/ -static gboolean +static gboolean pk_backend_update_packages_download_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; guint sub; if (_progress_percentage == 100) { @@ -925,7 +879,7 @@ * pk_backend_update_packages: */ void -pk_backend_update_packages(PkBackend * backend, gboolean only_trusted, gchar ** package_ids) +pk_backend_update_packages(PkBackend *backend, gboolean only_trusted, gchar **package_ids) { const gchar *eula_id; const gchar *license_agreement; @@ -982,10 +936,10 @@ _signal_timeout = g_timeout_add(200, pk_backend_update_packages_download_timeout, backend); } -static gboolean +static gboolean pk_backend_update_system_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_progress_percentage == 100) { /* cleanup socket stuff */ @@ -1054,8 +1008,8 @@ /** * pk_backend_socket_has_data_cb: **/ -static gboolean -pk_backend_socket_has_data_cb(GSocket * socket, GIOCondition condition, PkBackend * backend) +static gboolean +pk_backend_socket_has_data_cb(GSocket * socket, GIOCondition condition, PkBackend *backend) { GError *error = NULL; gsize len; @@ -1122,7 +1076,7 @@ * pk_backend_update_system: */ void -pk_backend_update_system(PkBackend * backend, gboolean only_trusted) +pk_backend_update_system(PkBackend *backend, gboolean only_trusted) { gchar *frontend_socket = NULL; GError *error = NULL; @@ -1194,7 +1148,7 @@ * pk_backend_get_repo_list: */ void -pk_backend_get_repo_list(PkBackend * backend, PkBitfield filters) +pk_backend_get_repo_list(PkBackend *backend, PkBitfield filters) { pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_repo_detail(backend, "fedora", @@ -1212,7 +1166,7 @@ * pk_backend_repo_enable: */ void -pk_backend_repo_enable(PkBackend * backend, const gchar * rid, gboolean enabled) +pk_backend_repo_enable(PkBackend *backend, const gchar *rid, gboolean enabled) { pk_backend_set_status(backend, PK_STATUS_ENUM_REQUEST); @@ -1238,7 +1192,7 @@ * pk_backend_repo_set_data: */ void -pk_backend_repo_set_data(PkBackend * backend, const gchar * rid, const gchar * parameter, const gchar * value) +pk_backend_repo_set_data(PkBackend *backend, const gchar *rid, const gchar *parameter, const gchar *value) { pk_backend_set_status(backend, PK_STATUS_ENUM_REQUEST); g_warning("REPO '%s' PARAMETER '%s' TO '%s'", rid, parameter, value); @@ -1263,10 +1217,10 @@ /** * pk_backend_what_provides_timeout: */ -static gboolean +static gboolean pk_backend_what_provides_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_progress_percentage == 100) { if (g_strcmp0(_values[0], "gstreamer0.10(decoder-audio/x-wma)(wmaversion=3)") == 0) { pk_backend_package(backend, PK_INFO_ENUM_AVAILABLE, @@ -1306,7 +1260,7 @@ * pk_backend_what_provides: */ void -pk_backend_what_provides(PkBackend * backend, PkBitfield filters, PkProvidesEnum provides, gchar ** values) +pk_backend_what_provides(PkBackend *backend, PkBitfield filters, PkProvidesEnum provides, gchar **values) { _progress_percentage = 0; _values = values; @@ -1321,7 +1275,7 @@ * pk_backend_get_packages: */ void -pk_backend_get_packages(PkBackend * backend, PkBitfield filters) +pk_backend_get_packages(PkBackend *backend, PkBitfield filters) { pk_backend_set_status(backend, PK_STATUS_ENUM_REQUEST); pk_backend_package(backend, PK_INFO_ENUM_INSTALLED, @@ -1334,7 +1288,7 @@ * pk_backend_download_packages: */ void -pk_backend_download_packages(PkBackend * backend, gchar ** package_ids, const gchar * directory) +pk_backend_download_packages(PkBackend *backend, gchar **package_ids, const gchar *directory) { gchar *filename; @@ -1363,7 +1317,7 @@ * pk_backend_simulate_install_packages: */ void -pk_backend_simulate_install_packages(PkBackend * backend, gchar ** package_ids) +pk_backend_simulate_install_packages(PkBackend *backend, gchar **package_ids) { pk_backend_set_status(backend, PK_STATUS_ENUM_DEP_RESOLVE); @@ -1395,10 +1349,10 @@ } -static gboolean +static gboolean pk_backend_upgrade_system_timeout(gpointer data) { - PkBackend *backend = (PkBackend *) data; + PkBackend *backend = (PkBackend *)data; if (_progress_percentage == 100) { pk_backend_require_restart(backend, PK_RESTART_ENUM_SYSTEM, "kernel;2.6.23-0.115.rc3.git1.fc8;i386;installed"); pk_backend_finished(backend); @@ -1444,7 +1398,7 @@ * pk_backend_upgrade_system: */ void -pk_backend_upgrade_system(PkBackend * backend, const gchar * distro_id, PkUpgradeKindEnum upgrade_kind) +pk_backend_upgrade_system(PkBackend *backend, const gchar *distro_id, PkUpgradeKindEnum upgrade_kind) { pk_backend_set_status(backend, PK_STATUS_ENUM_DOWNLOAD); pk_backend_set_allow_cancel(backend, TRUE); @@ -1456,7 +1410,7 @@ * pk_backend_transaction_start: */ void -pk_backend_transaction_start(PkBackend * backend) +pk_backend_transaction_start(PkBackend *backend) { /* here you would lock the backend */ pk_backend_message(backend, PK_MESSAGE_ENUM_AUTOREMOVE_IGNORED, "backend is crap"); @@ -1468,7 +1422,7 @@ * pk_backend_transaction_stop: */ void -pk_backend_transaction_stop(PkBackend * backend) +pk_backend_transaction_stop(PkBackend *backend) { /* here you would unlock the backend */ pk_backend_message(backend, PK_MESSAGE_ENUM_CONFIG_FILES_CHANGED, "backend is crap"); @@ -1489,7 +1443,7 @@ * pk_backend_get_description: */ gchar * -pk_backend_get_description(PkBackend * backend) +pk_backend_get_description(PkBackend *backend) { return g_strdup("pkgng"); } @@ -1498,7 +1452,7 @@ * pk_backend_get_author: */ gchar * -pk_backend_get_author(PkBackend * backend) +pk_backend_get_author(PkBackend *backend) { return g_strdup("Matt Windsor "); } From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 20:27:50 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id AFD3E612 for ; Mon, 24 Jun 2013 20:27:50 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9FDB31E3B for ; Mon, 24 Jun 2013 20:27:50 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OKRo6a004721 for ; Mon, 24 Jun 2013 20:27:50 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OKRohx004719 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 20:27:50 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 24 Jun 2013 20:27:50 GMT Message-Id: <201306242027.r5OKRohx004719@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253445 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 20:27:50 -0000 Author: dpl Date: Mon Jun 24 20:27:50 2013 New Revision: 253445 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253445 Log: Passing FDs :D Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 19:57:25 2013 (r253444) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 20:27:50 2013 (r253445) @@ -222,72 +222,64 @@ Int32 workFactor; #if CAPSICUM == 1 -int sv[2], fds[2], len; -int sendfds(int, int*); -int recvfds(int); +int sv[2], len; + +int sendfd(int, int); +int recvfd(int); int -sendfds(int s, int fd[2]) +sendfd(int s, int fd) { - char buf[1]; - struct iovec iov; - struct msghdr msg; - struct cmsghdr *cmsg; - char cms[CMSG_SPACE(2*sizeof(int))]; - - buf[0] = 0; - iov.iov_base = buf; - iov.iov_len = 1; - - memset(&msg, 0, sizeof msg); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)cms; - msg.msg_controllen = CMSG_LEN(2*sizeof(int)); - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - memmove(CMSG_DATA(cmsg), &fd, 2*sizeof(int)); - - if((sendmsg(s, &msg, 0)) != (int)iov.iov_len) - return -1; - return 0; + char buf[1] = { 0 }; + struct iovec iov; + iov.iov_base = buf; + iov.iov_len = 1; + + struct msghdr msg; + char cms[CMSG_SPACE(sizeof(int))]; + bzero(&msg, sizeof msg); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (caddr_t)cms; + msg.msg_controllen = CMSG_LEN(sizeof(int)); + + struct cmsghdr *cmsg; + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + memcpy(CMSG_DATA(cmsg), &fd, sizeof(int)); + + if((sendmsg(s, &msg, 0)) != (int)iov.iov_len) + return -1; + return 0; } int -recvfds(int s) +recvfd(int s) { - int n; - int fds[2]; - char buf[1]; - struct iovec iov; - struct msghdr msg; - struct cmsghdr *cmsg; - char cms[CMSG_SPACE(2*sizeof(int))]; - - iov.iov_base = buf; - iov.iov_len = 1; - - memset(&msg, 0, sizeof msg); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - msg.msg_control = (caddr_t)cms; - msg.msg_controllen = sizeof cms; - - if((n = recvmsg(s, &msg, 0)) < 0) - return -1; - if(n == 0){ - fprintf ( stderr, - "\n%s: recvfds: Unexpected EOF.\n", - progName); - return -1; - } - cmsg = CMSG_FIRSTHDR(&msg); - memmove(&fds, CMSG_DATA(cmsg), sizeof(int)); - return fds; + int fd; + struct cmsghdr *cmsg; + + char buf[1] = { 0 }; + struct iovec iov; + iov.iov_base = buf; + iov.iov_len = 1; + + struct msghdr msg; + char cms[CMSG_SPACE(sizeof(int))]; + msg.msg_name = 0; + msg.msg_namelen = 0; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (caddr_t)cms; + msg.msg_controllen = sizeof cms; + + if((recvmsg(s, &msg, 0)) <= 0) + return -1; + cmsg = CMSG_FIRSTHDR(&msg); + memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); + return fd; } #endif @@ -1044,9 +1036,6 @@ FILE* fp; IntNative fh; fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR); -# if CAPSICUM - cap_rights_limit(fh, CAP_WRITE); -# endif if (fh == -1) return NULL; fp = fdopen(fh, mode); if (fp == NULL) close(fh); @@ -1220,7 +1209,7 @@ FILE *outStr; Int32 n, i; # if CAPSICUM - Int32 infd; + Int32 fd; pid_t forkpid; # endif struct MY_STAT statBuf; @@ -1310,16 +1299,6 @@ saveInputFileMetaInfo ( inName ); } - if ( srcMode != SM_I2O ){ -# if CAPSICUM - infd = open( inName, O_RDONLY ); - cap_rights_limit(infd, CAP_READ); - inStr = fdopen ( infd, "rb" ); -# else - inStr = fopen ( inName, "rb" ); -# endif - } - switch ( srcMode ) { case SM_I2O: @@ -1344,6 +1323,7 @@ progName ); fprintf ( stderr, "%s: For help, type: `%s --help'.\n", progName, progName ); + inStr = fopen ( inName, "rb" ); if ( inStr != NULL ) fclose ( inStr ); setExit(1); return; @@ -1361,6 +1341,7 @@ if ( outStr == NULL) { fprintf ( stderr, "%s: Can't create output file %s: %s.\n", progName, outName, strerror(errno) ); + inStr = fopen ( inName, "rb" ); if ( inStr != NULL ) fclose ( inStr ); setExit(1); return; @@ -1389,10 +1370,25 @@ /* Pass the limited file descriptors with a unix domain socket. */ switch( forkpid = rfork(RFPROC | RFCFDG) ) { case ( 0 ): - /* revmsg() the FDs */ - if (cap_enter() < 0) { + if (fd == recvfd(sv[1]) <= 0){ fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", - progName, strerror(errno) ); + progName, strerror(errno) ); + exit(1); + } + printf("inStr fd receiverd: %d\n",fd); + inStr = fdopen(fd, "rb"); + + if (fd == recvfd(sv[1]) <= 0){ + fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", + progName, strerror(errno) ); + exit(1); + } + outStr = fdopen(fd, "wb"); + printf("outStr fd receiverd: %d\n",fd); + + if (cap_enter() < 0) { + fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", + progName, strerror(errno) ); exit(1); } @@ -1423,12 +1419,18 @@ exit(1); default: - + fd = fileno(inStr); + cap_rights_limit(fd, CAP_READ); + sendfd(sv[0], fd); + printf("Sending inStr fd: %d\n", fd); + fd = fileno(outStr); + cap_rights_limit(fd, CAP_WRITE); + sendfd(sv[0], fd); + printf("Sending outStr fd: %d\n", fd); wait(NULL); return; } # endif - } @@ -1439,6 +1441,10 @@ FILE *inStr; FILE *outStr; Int32 n, i; +/*# if CAPSICUM*/ + /*Int32 infd;*/ + /*pid_t forkpid;*/ +/*# endif*/ Bool magicNumberOK; Bool cantGuess; struct MY_STAT statBuf; @@ -1531,16 +1537,6 @@ saveInputFileMetaInfo ( inName ); } - if ( srcMode != SM_I2O ){ -/*# if CAPSICUM*/ - /*infd = open( inName, O_RDONLY );*/ - /*cap_rights_limit(infd, CAP_READ);*/ - /*inStr = fdopen ( infd, "rb" );*/ -/*# else*/ - inStr = fopen ( inName, "rb" ); -/*# endif*/ - } - switch ( srcMode ) { case SM_I2O: @@ -1558,6 +1554,7 @@ break; case SM_F2O: + inStr = fopen ( inName, "rb" ); outStr = stdout; if ( inStr == NULL ) { fprintf ( stderr, "%s: Can't open input file %s:%s.\n", @@ -1569,6 +1566,7 @@ break; case SM_F2F: + inStr = fopen ( inName, "rb" ); outStr = fopen_output_safely ( outName, "wb" ); if ( outStr == NULL) { fprintf ( stderr, "%s: Can't create output file %s: %s.\n", @@ -2088,19 +2086,10 @@ } # if CAPSICUM - if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1 ){ fprintf ( stderr, "%s: Can't create socket: %s.\n", progName, strerror(errno) ); exit(1); } - - /* XXX - Factorize code here */ - /*if (srcMode == SM_I2O) {*/ - /*if (opMode == OM_Z )*/ - /*compress( NULL );*/ - /*else if (opMode == OM_UNZ )*/ - /*uncompress (NULL);*/ - /*}*/ # endif if (opMode == OM_Z) { From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 20:35:49 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A5DD17FA for ; Mon, 24 Jun 2013 20:35:49 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 978621EA3 for ; Mon, 24 Jun 2013 20:35:49 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OKZnHw069371 for ; Mon, 24 Jun 2013 20:35:49 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OKZnXV069365 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 20:35:49 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 24 Jun 2013 20:35:49 GMT Message-Id: <201306242035.r5OKZnXV069365@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253446 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 20:35:49 -0000 Author: dpl Date: Mon Jun 24 20:35:49 2013 New Revision: 253446 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253446 Log: Use FD passing in compression. (Not in uncompress() ) Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 20:27:50 2013 (r253445) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jun 24 20:35:49 2013 (r253446) @@ -1441,10 +1441,6 @@ FILE *inStr; FILE *outStr; Int32 n, i; -/*# if CAPSICUM*/ - /*Int32 infd;*/ - /*pid_t forkpid;*/ -/*# endif*/ Bool magicNumberOK; Bool cantGuess; struct MY_STAT statBuf; @@ -2085,13 +2081,6 @@ # endif } -# if CAPSICUM - if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1 ){ - fprintf ( stderr, "%s: Can't create socket: %s.\n", progName, strerror(errno) ); - exit(1); - } -# endif - if (opMode == OM_Z) { if (srcMode == SM_I2O) { compress ( NULL ); From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 21:03:11 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 07919624 for ; Mon, 24 Jun 2013 21:03:11 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id DCAF11FC1 for ; Mon, 24 Jun 2013 21:03:10 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OL3Ab4006313 for ; Mon, 24 Jun 2013 21:03:10 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OL3AWw006268 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 21:03:10 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 21:03:10 GMT Message-Id: <201306242103.r5OL3AWw006268@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253451 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 21:03:11 -0000 Author: mattbw Date: Mon Jun 24 21:03:10 2013 New Revision: 253451 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253451 Log: tidy up so that WARNS=6 works Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/db.c soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/groups.c soc2013/mattbw/backend/groups.h soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/Makefile Mon Jun 24 21:03:10 2013 (r253451) @@ -4,10 +4,14 @@ SHLIB_MAJOR= 1 SRCS= pk-backend-pkgng.c get-details.c groups.c db.c +LIBDIR= /usr/local/lib/packagekit-backend + USE_PK_PKGCONF= 0 PKGS= pkg gio-2.0 gio-unix-2.0 +# 0.6.* versions of PackageKit do not export pkgconf information, so here's a +# bodge. .if USE_PK_PKGCONF PKGS+= packagekit-glib2 .else Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/db.c Mon Jun 24 21:03:10 2013 (r253451) @@ -23,6 +23,8 @@ #include "pk-backend.h" #include "pkg.h" +#include "db.h" /* prototypes */ + /* * Opens a pkgdb ready for remote operations. This will always return TRUE if * and only if a database ready for use is now pointed to by *db, and FALSE Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/get-details.c Mon Jun 24 21:03:10 2013 (r253451) @@ -24,18 +24,37 @@ #include "pk-backend.h" #include "pkg.h" -#include "groups.h" +#include "db.h" /* open_remote_db */ +#include "groups.h" /* group_from_origin */ +#include "get-details.h" /* get_details_thread prototype */ +/* TODO: move out of get-details? */ +gboolean string_match(const char *left, const char *right); static gboolean -get_local_details(gchar *name, - gchar *version, - gchar *arch, +get_local_details(const gchar *name, + const gchar *version, + const gchar *arch, PkBackend *backend, struct pkgdb *db); -static gboolean +static gboolean +get_remote_details(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, + PkBackend *backend, + struct pkgdb *db); +static gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); +gboolean +get_details_check_matches(struct pkgdb_it *matches, + const gchar *id_name, + const gchar *id_version, + const gchar *id_arch, + const gchar *id_data, + PkBackend *backend); + /* * Checks two strings with strcmp and emits TRUE if they match. If either @@ -61,10 +80,10 @@ */ gboolean get_details_check_matches(struct pkgdb_it *matches, - gchar *id_name, - gchar *id_version, - gchar *id_arch, - gchar *id_data, + const gchar *id_name, + const gchar *id_version, + const gchar *id_arch, + const gchar *id_data, PkBackend *backend) { gboolean found; @@ -84,7 +103,6 @@ const char *reponame; const char *version; const char *www; - pkg_t type; int64_t flatsize; pkg_get(match, @@ -144,9 +162,9 @@ /* Looks the split PackageID up in the local database. */ static gboolean -get_local_details(gchar *name, - gchar *version, - gchar *arch, +get_local_details(const gchar *name, + const gchar *version, + const gchar *arch, PkBackend *backend, struct pkgdb *db) { @@ -167,10 +185,10 @@ /* Looks the split PackageID up in the remote database. */ gboolean -get_remote_details(gchar *name, - gchar *version, - gchar *arch, - gchar *reponame, +get_remote_details(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, PkBackend *backend, struct pkgdb *db) { @@ -203,7 +221,6 @@ PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); else { - struct pkgdb_it *packages; /* Parts of the package ID */ gchar *name; gchar *version; Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/groups.c Mon Jun 24 21:03:10 2013 (r253451) @@ -18,23 +18,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include /* NULL */ -#include /* strdup */ +#include /* NULL */ +#include /* strdup */ -#include "glib.h" /* g_strcmp0 */ -#include "pk-backend.h" /* PkGroupEnum, PK_* */ +#include "glib.h" /* g_strcmp0 */ +#include "pk-backend.h" /* PkGroupEnum, PK_* */ + +#include "groups.h" /* prototypes */ struct group_mapping { - const char *dir; - PkGroupEnum group; + const char *dir; + PkGroupEnum group; }; -/* Mappings between ports directories (as in the first part of PKG_ORIGIN) and - * PackageKit enums. - * +/* + * Mappings between ports directories (as in the first part of PKG_ORIGIN) + * and PackageKit enums. + * * Some of these mappings are a bit iffy, peer review would be greatly * appreciated. - */ + */ static struct group_mapping group_mappings[] = { {"accessibility", PK_GROUP_ENUM_ACCESSIBILITY}, {"arabic", PK_GROUP_ENUM_LOCALIZATION}, @@ -43,18 +46,18 @@ {"audio", PK_GROUP_ENUM_MULTIMEDIA}, {"benchmarks", PK_GROUP_ENUM_PROGRAMMING}, {"biology", PK_GROUP_ENUM_SCIENCE}, - {"cad", PK_GROUP_ENUM_SCIENCE}, /* dubious */ + {"cad", PK_GROUP_ENUM_SCIENCE}, /* dubious */ {"chinese", PK_GROUP_ENUM_LOCALIZATION}, {"comms", PK_GROUP_ENUM_COMMUNICATION}, - {"converters", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */ - {"databases", PK_GROUP_ENUM_SERVERS}, /* dubious */ + {"converters", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */ + {"databases", PK_GROUP_ENUM_SERVERS}, /* dubious */ {"deskutils", PK_GROUP_ENUM_ACCESSORIES}, {"devel", PK_GROUP_ENUM_PROGRAMMING}, - {"distfiles", PK_GROUP_ENUM_OTHER}, /* ?? */ + {"distfiles", PK_GROUP_ENUM_OTHER}, /* ?? */ {"dns", PK_GROUP_ENUM_NETWORK}, - {"editors", PK_GROUP_ENUM_OFFICE}, /* dubious */ - {"emulators", PK_GROUP_ENUM_OTHER}, /* ?? */ - {"finance", PK_GROUP_ENUM_OFFICE}, /* dubious */ + {"editors", PK_GROUP_ENUM_OFFICE}, /* dubious */ + {"emulators", PK_GROUP_ENUM_OTHER}, /* ?? */ + {"finance", PK_GROUP_ENUM_OFFICE}, /* dubious */ {"french", PK_GROUP_ENUM_LOCALIZATION}, {"ftp", PK_GROUP_ENUM_NETWORK}, {"games", PK_GROUP_ENUM_GAMES}, @@ -74,23 +77,23 @@ {"net", PK_GROUP_ENUM_NETWORK}, {"net-im", PK_GROUP_ENUM_COMMUNICATION}, {"net-mgmt", PK_GROUP_ENUM_NETWORK}, - {"net-p2p", PK_GROUP_ENUM_NETWORK}, /* possibly COMMUNICATION */ - {"news", PK_GROUP_ENUM_COMMUNICATION}, /* ?? */ - {"packages", PK_GROUP_ENUM_OTHER}, /* ?? */ + {"net-p2p", PK_GROUP_ENUM_NETWORK}, /* possibly COMMUNICATION */ + {"news", PK_GROUP_ENUM_COMMUNICATION}, /* ?? */ + {"packages", PK_GROUP_ENUM_OTHER}, /* ?? */ {"palm", PK_GROUP_ENUM_OTHER}, {"polish", PK_GROUP_ENUM_LOCALIZATION}, - {"ports-mgmt", PK_GROUP_ENUM_ADMIN_TOOLS}, /* dubious? */ + {"ports-mgmt", PK_GROUP_ENUM_ADMIN_TOOLS}, /* dubious? */ {"portuguese", PK_GROUP_ENUM_LOCALIZATION}, - {"print", PK_GROUP_ENUM_OFFICE}, /* dubious */ + {"print", PK_GROUP_ENUM_OFFICE}, /* dubious */ {"russian", PK_GROUP_ENUM_LOCALIZATION}, {"science", PK_GROUP_ENUM_SCIENCE}, {"security", PK_GROUP_ENUM_SECURITY}, - {"shells", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */ + {"shells", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */ {"sysutils", PK_GROUP_ENUM_ADMIN_TOOLS}, - {"textproc", PK_GROUP_ENUM_PUBLISHING}, /* dubious */ + {"textproc", PK_GROUP_ENUM_PUBLISHING}, /* dubious */ {"ukrainian", PK_GROUP_ENUM_LOCALIZATION}, {"vietnamese", PK_GROUP_ENUM_LOCALIZATION}, - {"www", PK_GROUP_ENUM_NETWORK}, /* could be COMMUNICATION? prob. not */ + {"www", PK_GROUP_ENUM_NETWORK}, /* could be COMMUNICATION? prob. not */ /* Some of the X directories could be better classified possibly */ {"x11", PK_GROUP_ENUM_DESKTOP_OTHER}, {"x11-clocks", PK_GROUP_ENUM_DESKTOP_OTHER}, @@ -105,30 +108,43 @@ {NULL, PK_GROUP_ENUM_UNKNOWN} }; +/* Reports the PackageKit groups available on this backend as a bitfield. */ +PkBitfield +available_groups(void) +{ + int i; + PkBitfield bits; + + bits = 0; + for (i = 0; group_mappings[i].dir != NULL; i++) + pk_bitfield_add(bits, group_mappings[i].group); + + return bits; +} + /* Maps from port/origin directories to PackageKit groups. */ PkGroupEnum group_from_port_dir(const char *port_dir) { - int i; + int i; i = 0; while (group_mappings[i].dir != NULL && - g_strcmp0(group_mappings[i].dir, port_dir) != 0) + g_strcmp0(group_mappings[i].dir, port_dir) != 0) i++; return group_mappings[i].group; -} +} /* Maps from package origins to PackageKit groups. */ PkGroupEnum group_from_origin(const char *origin) { - char *dir; - int i; - PkGroupEnum group; + char *dir; + int i; + PkGroupEnum group; /* Find the separation between dir and port name */ - for (i = 0; origin[i] != '/' && origin[i] != '\0'; i++) - ; + for (i = 0; origin[i] != '/' && origin[i] != '\0'; i++); /* Is this a valid origin? If not, we want the default group */ if (origin[i] == '\0') Modified: soc2013/mattbw/backend/groups.h ============================================================================== --- soc2013/mattbw/backend/groups.h Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/groups.h Mon Jun 24 21:03:10 2013 (r253451) @@ -23,12 +23,8 @@ #include "pk-backend.h" -PkGroupEnum group_from_port_dir(const char *port_dir); - -PkGroupEnum group_from_origin(const char *origin); - -#endif /* _PKGNG_BACKEND_GROUPS_H_ */ - - - +PkBitfield available_groups(void); +PkGroupEnum group_from_origin(const char *origin); +PkGroupEnum group_from_port_dir(const char *port_dir); +#endif /* _PKGNG_BACKEND_GROUPS_H_ */ Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 20:58:54 2013 (r253450) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Mon Jun 24 21:03:10 2013 (r253451) @@ -30,7 +30,10 @@ #include "pk-backend.h" #include "pkg.h" -#include "get-details.h" +#include "groups.h" /* available_groups */ +#include "get-details.h" /* get_details_thread */ + +#define INTENTIONALLY_IGNORE(x) (void)(x) /* static bodges */ static guint _progress_percentage = 0; @@ -56,13 +59,6 @@ static GSocket *_socket = NULL; static guint _socket_listen_id = 0; -struct pkgng_private { - struct pkgdb *db; -}; - -static struct pkgng_private priv; - - /** * pk_backend_initialize: */ @@ -86,19 +82,20 @@ void pk_backend_destroy(PkBackend *backend) { + INTENTIONALLY_IGNORE(backend); pkg_shutdown(); } -/** - * pk_backend_get_groups: +/* + * Return all groups available from this backend. + * + * The business end of this function is in "groups.c". */ PkBitfield pk_backend_get_groups(PkBackend *backend) { - return pk_bitfield_from_enums(PK_GROUP_ENUM_ACCESSIBILITY, - PK_GROUP_ENUM_GAMES, - PK_GROUP_ENUM_SYSTEM, - -1); + INTENTIONALLY_IGNORE(backend); + return available_groups(); } /** @@ -107,6 +104,7 @@ PkBitfield pk_backend_get_filters(PkBackend *backend) { + INTENTIONALLY_IGNORE(backend); return pk_bitfield_from_enums(PK_FILTER_ENUM_GUI, PK_FILTER_ENUM_INSTALLED, PK_FILTER_ENUM_DEVELOPMENT, @@ -119,6 +117,7 @@ gchar * pk_backend_get_mime_types(PkBackend *backend) { + INTENTIONALLY_IGNORE(backend); return g_strdup("application/x-rpm;application/x-deb"); } @@ -161,6 +160,9 @@ void pk_backend_get_depends(PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive) { + INTENTIONALLY_IGNORE(filters); + INTENTIONALLY_IGNORE(recursive); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); if (g_strcmp0(package_ids[0], "scribus;1.3.4-1.fc8;i386;fedora") == 0) { @@ -184,6 +186,8 @@ void pk_backend_get_details(PkBackend *backend, gchar **package_ids) { + INTENTIONALLY_IGNORE(package_ids); /* can be retrieved from backend */ + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); @@ -240,6 +244,10 @@ void pk_backend_get_requires(PkBackend *backend, PkBitfield filters, gchar **package_ids, gboolean recursive) { + INTENTIONALLY_IGNORE(filters); + INTENTIONALLY_IGNORE(package_ids); + INTENTIONALLY_IGNORE(recursive); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_package(backend, PK_INFO_ENUM_INSTALLED, "glib2;2.14.0;i386;fedora", "The GLib library"); @@ -386,6 +394,8 @@ void pk_backend_get_updates(PkBackend *backend, PkBitfield filters) { + INTENTIONALLY_IGNORE(filters); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); /* check network state */ @@ -548,6 +558,9 @@ void pk_backend_install_files(PkBackend *backend, gboolean only_trusted, gchar **full_paths) { + INTENTIONALLY_IGNORE(only_trusted); + INTENTIONALLY_IGNORE(full_paths); + pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL); pk_backend_set_percentage(backend, 101); _signal_timeout = g_timeout_add(2000, pk_backend_install_files_timeout, backend); @@ -577,6 +590,8 @@ void pk_backend_refresh_cache(PkBackend *backend, gboolean force) { + INTENTIONALLY_IGNORE(force); + _progress_percentage = 0; /* reset */ @@ -694,6 +709,10 @@ void pk_backend_remove_packages(PkBackend *backend, gchar **package_ids, gboolean allow_deps, gboolean autoremove) { + INTENTIONALLY_IGNORE(package_ids); + INTENTIONALLY_IGNORE(allow_deps); + INTENTIONALLY_IGNORE(autoremove); + pk_backend_set_status(backend, PK_STATUS_ENUM_REMOVE); pk_backend_error_code(backend, PK_ERROR_ENUM_NO_NETWORK, "No network connection available"); pk_backend_finished(backend); @@ -705,6 +724,9 @@ void pk_backend_search_details(PkBackend *backend, PkBitfield filters, gchar **values) { + INTENTIONALLY_IGNORE(filters); + INTENTIONALLY_IGNORE(values); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); pk_backend_package(backend, PK_INFO_ENUM_AVAILABLE, @@ -719,6 +741,8 @@ void pk_backend_search_files(PkBackend *backend, PkBitfield filters, gchar **values) { + INTENTIONALLY_IGNORE(values); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); if (!pk_bitfield_contain(filters, PK_FILTER_ENUM_INSTALLED)) @@ -738,6 +762,9 @@ void pk_backend_search_groups(PkBackend *backend, PkBitfield filters, gchar **values) { + INTENTIONALLY_IGNORE(filters); + INTENTIONALLY_IGNORE(values); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_allow_cancel(backend, TRUE); pk_backend_package(backend, PK_INFO_ENUM_AVAILABLE, @@ -788,6 +815,9 @@ void pk_backend_search_names(PkBackend *backend, PkBitfield filters, gchar **values) { + INTENTIONALLY_IGNORE(filters); + INTENTIONALLY_IGNORE(values); + pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); pk_backend_set_allow_cancel(backend, TRUE); pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); @@ -886,6 +916,7 @@ gboolean has_eula; /* FIXME: support only_trusted */ + INTENTIONALLY_IGNORE(only_trusted); if (_use_gpg && !_has_signature) { pk_backend_repo_signature_required(backend, package_ids[0], "updates", @@ -1085,6 +1116,8 @@ gsize wrote; GSource *source; + INTENTIONALLY_IGNORE(only_trusted); + pk_backend_set_status(backend, PK_STATUS_ENUM_DOWNLOAD); pk_backend_set_allow_cancel(backend, TRUE); _progress_percentage = 0; @@ -1262,6 +1295,8 @@ void pk_backend_what_provides(PkBackend *backend, PkBitfield filters, PkProvidesEnum provides, gchar **values) { + INTENTIONALLY_IGNORE(provides); + _progress_percentage = 0; _values = values; _signal_timeout = g_timeout_add(200, pk_backend_what_provides_timeout, backend); @@ -1277,6 +1312,8 @@ void pk_backend_get_packages(PkBackend *backend, PkBitfield filters) { + INTENTIONALLY_IGNORE(filters); + pk_backend_set_status(backend, PK_STATUS_ENUM_REQUEST); pk_backend_package(backend, PK_INFO_ENUM_INSTALLED, "update1;2.19.1-4.fc8;i386;fedora", @@ -1292,6 +1329,8 @@ { gchar *filename; + INTENTIONALLY_IGNORE(package_ids); + pk_backend_set_status(backend, PK_STATUS_ENUM_DOWNLOAD); /* first package */ @@ -1319,6 +1358,8 @@ void pk_backend_simulate_install_packages(PkBackend *backend, gchar **package_ids) { + INTENTIONALLY_IGNORE(package_ids); + pk_backend_set_status(backend, PK_STATUS_ENUM_DEP_RESOLVE); pk_backend_package(backend, PK_INFO_ENUM_REMOVING, @@ -1400,6 +1441,9 @@ void pk_backend_upgrade_system(PkBackend *backend, const gchar *distro_id, PkUpgradeKindEnum upgrade_kind) { + INTENTIONALLY_IGNORE(distro_id); + INTENTIONALLY_IGNORE(upgrade_kind); + pk_backend_set_status(backend, PK_STATUS_ENUM_DOWNLOAD); pk_backend_set_allow_cancel(backend, TRUE); _progress_percentage = 0; @@ -1445,6 +1489,7 @@ gchar * pk_backend_get_description(PkBackend *backend) { + INTENTIONALLY_IGNORE(backend); return g_strdup("pkgng"); } @@ -1454,5 +1499,6 @@ gchar * pk_backend_get_author(PkBackend *backend) { + INTENTIONALLY_IGNORE(backend); return g_strdup("Matt Windsor "); } From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 21:10:52 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E79BC82F for ; Mon, 24 Jun 2013 21:10:52 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id D92FE1020 for ; Mon, 24 Jun 2013 21:10:52 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OLAqT2081447 for ; Mon, 24 Jun 2013 21:10:52 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OLAqKF081438 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 21:10:52 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 21:10:52 GMT Message-Id: <201306242110.r5OLAqKF081438@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253452 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 21:10:53 -0000 Author: mattbw Date: Mon Jun 24 21:10:52 2013 New Revision: 253452 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253452 Log: Move USE_PK_PKGCONF to underneath its comment Modified: soc2013/mattbw/backend/Makefile Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Mon Jun 24 21:03:10 2013 (r253451) +++ soc2013/mattbw/backend/Makefile Mon Jun 24 21:10:52 2013 (r253452) @@ -6,12 +6,11 @@ LIBDIR= /usr/local/lib/packagekit-backend -USE_PK_PKGCONF= 0 - PKGS= pkg gio-2.0 gio-unix-2.0 # 0.6.* versions of PackageKit do not export pkgconf information, so here's a # bodge. +USE_PK_PKGCONF= 0 # Set to 1 if using recent PackageKit .if USE_PK_PKGCONF PKGS+= packagekit-glib2 .else From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 21:11:17 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 83FF2842 for ; Mon, 24 Jun 2013 21:11:17 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 7442F1024 for ; Mon, 24 Jun 2013 21:11:17 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OLBH7Y091648 for ; Mon, 24 Jun 2013 21:11:17 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OLBHEe091643 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 21:11:17 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 21:11:17 GMT Message-Id: <201306242111.r5OLBHEe091643@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253453 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 21:11:17 -0000 Author: mattbw Date: Mon Jun 24 21:11:17 2013 New Revision: 253453 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253453 Log: close bracket in comment Modified: soc2013/mattbw/backend/groups.c Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Mon Jun 24 21:10:52 2013 (r253452) +++ soc2013/mattbw/backend/groups.c Mon Jun 24 21:11:17 2013 (r253453) @@ -104,7 +104,7 @@ {"x11-themes", PK_GROUP_ENUM_DESKTOP_OTHER}, {"x11-toolkits", PK_GROUP_ENUM_DESKTOP_OTHER}, {"x11-wm", PK_GROUP_ENUM_DESKTOP_OTHER}, - /* Default (for new/unspecified ports directories */ + /* Default (for new/unspecified ports directories) */ {NULL, PK_GROUP_ENUM_UNKNOWN} }; From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 22:15:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 61B47699 for ; Mon, 24 Jun 2013 22:15:36 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 53C511259 for ; Mon, 24 Jun 2013 22:15:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OMFahB056276 for ; Mon, 24 Jun 2013 22:15:36 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OMFa0x056274 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 22:15:36 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 22:15:36 GMT Message-Id: <201306242215.r5OMFa0x056274@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253457 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 22:15:36 -0000 Author: mattbw Date: Mon Jun 24 22:15:36 2013 New Revision: 253457 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253457 Log: use strchr instead of rolling our own Modified: soc2013/mattbw/backend/groups.c Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Mon Jun 24 21:33:19 2013 (r253456) +++ soc2013/mattbw/backend/groups.c Mon Jun 24 22:15:36 2013 (r253457) @@ -19,13 +19,15 @@ */ #include /* NULL */ -#include /* strdup */ +#include /* strchr, strdup */ #include "glib.h" /* g_strcmp0 */ #include "pk-backend.h" /* PkGroupEnum, PK_* */ #include "groups.h" /* prototypes */ +const char ORIGIN_SEPARATOR = '/'; + struct group_mapping { const char *dir; PkGroupEnum group; @@ -140,20 +142,19 @@ group_from_origin(const char *origin) { char *dir; - int i; + char *sep; PkGroupEnum group; /* Find the separation between dir and port name */ - for (i = 0; origin[i] != '/' && origin[i] != '\0'; i++); - - /* Is this a valid origin? If not, we want the default group */ - if (origin[i] == '\0') - dir = NULL; - else - dir = strndup(origin, i); + sep = strchr(origin, ORIGIN_SEPARATOR); + /* Is this a valid origin (did it have a separator)? + * If not, we want the default group. + * If so, then the number of chars between the origin start and the + * separator mark the port directory name we want to use. + */ + dir = (sep == NULL ? NULL : strndup(origin, sep - origin)); group = group_from_port_dir(dir); - if (dir) free(dir); From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 23:00:06 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7B94C1C2 for ; Mon, 24 Jun 2013 23:00:06 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 5E1B515C2 for ; Mon, 24 Jun 2013 23:00:06 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5ON067M084985 for ; Mon, 24 Jun 2013 23:00:06 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5ON068D084963 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 23:00:06 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 23:00:06 GMT Message-Id: <201306242300.r5ON068D084963@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253458 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 23:00:06 -0000 Author: mattbw Date: Mon Jun 24 23:00:06 2013 New Revision: 253458 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253458 Log: unify get_remote_details and get_local_details Modified: soc2013/mattbw/backend/get-details.c Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 22:15:36 2013 (r253457) +++ soc2013/mattbw/backend/get-details.c Mon Jun 24 23:00:06 2013 (r253458) @@ -31,19 +31,13 @@ /* TODO: move out of get-details? */ gboolean string_match(const char *left, const char *right); static gboolean -get_local_details(const gchar *name, +get_details_query(const gchar *name, const gchar *version, const gchar *arch, + const gchar *reponame, PkBackend *backend, struct pkgdb *db); static gboolean -get_remote_details(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db); -static gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); @@ -160,11 +154,19 @@ return found; } -/* Looks the split PackageID up in the local database. */ +/* + * Looks the split PackageID up in the package databases. + * + * Usually, a remote query will be done on the repository named by "reponame". + * If reponame is NULL, a remote check will be done against all repostories. + * If it is "installed", a local check will be done. (This is in keeping + * with the special meaning of the "installed" repository in PackageIDs). + */ static gboolean -get_local_details(const gchar *name, +get_details_query(const gchar *name, const gchar *version, const gchar *arch, + const gchar *reponame, PkBackend *backend, struct pkgdb *db) { @@ -172,31 +174,12 @@ gboolean success; success = FALSE; - it = pkgdb_query(db, name, MATCH_EXACT); - if (it) - success = get_details_check_matches(it, - name, - version, - arch, - "installed", - backend); - return success; -} -/* Looks the split PackageID up in the remote database. */ -gboolean -get_remote_details(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db) -{ - struct pkgdb_it *it; - gboolean success; - - success = FALSE; - it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); + /* Are we doing a local query? */ + if (g_strcmp0(reponame, "installed") == 0) + it = pkgdb_query(db, name, MATCH_EXACT); + else + it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); if (it) success = get_details_check_matches(it, name, @@ -246,22 +229,27 @@ /* - * If the PackageID is for an installed package, do a local - * query. If it is for a specific repo, do a remote query on - * it. And if the PackageID has no repository information at - * all, check both local and repo-generic remote. (TODO: - * local packages?) + * If the PackageID has a repository specified (even if it's + * "installed" i.e. currently installed package), running + * "get_details_query" directly should handle remote/local + * queries properly. + * + * If there is no repository specified, however (data is NULL), + * we may need to check both the local and (all) remote + * repositories, in that order. (TODO: local packages?) */ - if (g_strcmp0(data, "installed") == 0) - success = get_local_details(name, version, arch, backend, db); - else if (data != NULL) /* FIXME: treats 'local' as repo */ - success = get_remote_details(name, version, arch, data, backend, db); - else { - /* TODO: ensure this is correct behaviour */ - success = get_local_details(name, version, arch, backend, db); + if (data == NULL) { + /* Try local database first. */ + success = get_details_query(name, + version, + arch, + "installed", + backend, + db); if (success == FALSE) - success = get_remote_details(name, version, arch, data, backend, db); - } + success = get_details_query(name, version, NULL, data, backend, db); + } else + success = get_details_query(name, version, arch, data, backend, db); /* * Assume any error is due to not finding packages. At time * of writing this is true, but may change. From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 00:08:27 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6405CAD9 for ; Tue, 25 Jun 2013 00:08:27 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 4673917CE for ; Tue, 25 Jun 2013 00:08:27 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P08Q9n089669 for ; Tue, 25 Jun 2013 00:08:26 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P08Qog089650 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 00:08:26 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 00:08:26 GMT Message-Id: <201306250008.r5P08Qog089650@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253461 - in soc2013/mattbw: backend dummy tests tests/licence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 00:08:27 -0000 Author: mattbw Date: Tue Jun 25 00:08:26 2013 New Revision: 253461 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253461 Log: get rid of dummy; add in testing for the licence part of get-details Added: soc2013/mattbw/tests/ soc2013/mattbw/tests/licence/ soc2013/mattbw/tests/licence/Makefile soc2013/mattbw/tests/licence/lictest.c Deleted: soc2013/mattbw/dummy/ Modified: soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/groups.c Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Mon Jun 24 23:41:16 2013 (r253460) +++ soc2013/mattbw/backend/get-details.c Tue Jun 25 00:08:26 2013 (r253461) @@ -29,6 +29,7 @@ #include "get-details.h" /* get_details_thread prototype */ /* TODO: move out of get-details? */ +const char *null_if_empty(const char *in); gboolean string_match(const char *left, const char *right); static gboolean get_details_query(const gchar *name, @@ -190,6 +191,18 @@ return success; } +/* + * If the input pointer points to a string that is empty, return the null + * pointer; else pass through the pointer unmolested. + * + * This does NOT free anything! + */ +const char * +null_if_empty(const char *in) +{ + return (in != NULL && strlen(in) == 0) ? NULL : in; +} + gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) { @@ -205,28 +218,19 @@ "invalid package id"); else { /* Parts of the package ID */ - gchar *name; - gchar *version; - gchar *arch; - gchar *data; - - name = parts[PK_PACKAGE_ID_NAME]; - if (name != NULL && strlen(name) == 0) - name = NULL; - - version = parts[PK_PACKAGE_ID_VERSION]; - if (version != NULL && strlen(version) == 0) - version = NULL; - - arch = parts[PK_PACKAGE_ID_ARCH]; - if (arch != NULL && strlen(arch) == 0) - arch = NULL; - - data = parts[PK_PACKAGE_ID_DATA]; - if (data != NULL && strlen(data) == 0) - data = NULL; - + const gchar *name; + const gchar *version; + const gchar *arch; + const gchar *data; + /* + * Make really really REALLY sure that the PackageID fields + * either have sensible data in them, or are NULL. + */ + name = null_if_empty(parts[PK_PACKAGE_ID_NAME]); + version = null_if_empty(parts[PK_PACKAGE_ID_VERSION]); + arch = null_if_empty(parts[PK_PACKAGE_ID_ARCH]); + data = null_if_empty(parts[PK_PACKAGE_ID_DATA]); /* * If the PackageID has a repository specified (even if it's Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Mon Jun 24 23:41:16 2013 (r253460) +++ soc2013/mattbw/backend/groups.c Tue Jun 25 00:08:26 2013 (r253461) @@ -26,7 +26,7 @@ #include "groups.h" /* prototypes */ -const char ORIGIN_SEPARATOR = '/'; +const char ORIGIN_SEPARATOR = '/'; struct group_mapping { const char *dir; @@ -39,6 +39,10 @@ * * Some of these mappings are a bit iffy, peer review would be greatly * appreciated. + * + * These should ALWAYS be in alphabetical order of ports directories. This is + * in case anything relies on this property when searching this list (for + * example binary searching) */ static struct group_mapping group_mappings[] = { {"accessibility", PK_GROUP_ENUM_ACCESSIBILITY}, @@ -142,16 +146,17 @@ group_from_origin(const char *origin) { char *dir; - char *sep; + char *sep; PkGroupEnum group; /* Find the separation between dir and port name */ sep = strchr(origin, ORIGIN_SEPARATOR); - /* Is this a valid origin (did it have a separator)? - * If not, we want the default group. - * If so, then the number of chars between the origin start and the - * separator mark the port directory name we want to use. + /* + * Is this a valid origin (did it have a separator)? If not, we want + * the default group. If so, then the number of chars between the + * origin start and the separator mark the port directory name we + * want to use. */ dir = (sep == NULL ? NULL : strndup(origin, sep - origin)); group = group_from_port_dir(dir); Added: soc2013/mattbw/tests/licence/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/licence/Makefile Tue Jun 25 00:08:26 2013 (r253461) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= lictest +CFLAGS+= `pkgconf --cflags pkg` +LDFLAGS+= `pkgconf --libs pkg` + +.include Added: soc2013/mattbw/tests/licence/lictest.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/licence/lictest.c Tue Jun 25 00:08:26 2013 (r253461) @@ -0,0 +1,97 @@ +#include +#include +#include "pkg.h" + +void handle_it(struct pkgdb_it *it); +int getdb(struct pkgdb **db); + +int +getdb(struct pkgdb **db) +{ + int err; + + /* err = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_REPO); + + if (err == EPKG_ENOACCESS) + fprintf(stderr, "check your privilege\n", err); + else if (err != EPKG_OK) + fprintf(stderr, "access error: %i\n", err); + else */{ + err = pkgdb_open(db, PKGDB_REMOTE); + if (err != EPKG_OK) + fprintf(stderr, "open error: %i\n", err); + } + return err; +} + +int +main(int argc, char **argv) +{ + struct pkgdb *db; + int err; + + db = NULL; + + err = (argc == 2 ? EPKG_OK : EPKG_FATAL); + if (err == EPKG_OK) { + err = pkg_init(NULL); + if (err != EPKG_OK) + fprintf(stderr, "could not parse config file\n"); + } else + fprintf(stderr, "usage: %s name\n", argv[0]); + + if (err == EPKG_OK) + err = getdb(&db); + + if (err == EPKG_OK) { + struct pkgdb_it *it; + + it = pkgdb_query(db, argv[1], MATCH_EXACT); + if (it == NULL) + printf("no local matches!\n"); + else handle_it(it); + + it = pkgdb_rquery(db, argv[1], MATCH_EXACT, NULL); + if (it == NULL) + printf("no remote matches!\n"); + else handle_it(it); + + printf("shutting down\n"); + pkgdb_it_free(it); + pkgdb_close(db); + pkg_shutdown(); + printf("shutdown\n"); + } +} + + +void +handle_it(struct pkgdb_it *it) +{ + int err; + struct pkg *match; + + match = NULL; + do { + err = pkgdb_it_next(it, &match, PKG_LOAD_BASIC | PKG_LOAD_LICENSES); + if (err == EPKG_OK) { + const char *name; + struct pkg_license *lic; + int err2; + + lic = NULL; + + pkg_get(match, PKG_NAME, &name); + printf("name: %s\n", name); + + do { + err2 = pkg_licenses(match, &lic); + if (err2 == EPKG_OK) + printf(" licence: %s\n", pkg_license_name(lic)); + } while (err2 == EPKG_OK); + } + + } while (err == EPKG_OK); + + pkg_free(match); +} From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 01:12:25 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C3F0F7B8 for ; Tue, 25 Jun 2013 01:12:25 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B4C6219C9 for ; Tue, 25 Jun 2013 01:12:25 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P1CPm4014366 for ; Tue, 25 Jun 2013 01:12:25 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P1CPQH014360 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 01:12:25 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 01:12:25 GMT Message-Id: <201306250112.r5P1CPQH014360@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253466 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 01:12:25 -0000 Author: mattbw Date: Tue Jun 25 01:12:25 2013 New Revision: 253466 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253466 Log: adds license mapping (unused and untested at the moment). Added: soc2013/mattbw/backend/licenses.c soc2013/mattbw/backend/licenses.h soc2013/mattbw/backend/mappings.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/groups.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Tue Jun 25 00:29:59 2013 (r253465) +++ soc2013/mattbw/backend/Makefile Tue Jun 25 01:12:25 2013 (r253466) @@ -2,7 +2,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c get-details.c groups.c db.c +SRCS= pk-backend-pkgng.c get-details.c groups.c db.c licenses.c LIBDIR= /usr/local/lib/packagekit-backend Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Tue Jun 25 00:29:59 2013 (r253465) +++ soc2013/mattbw/backend/groups.c Tue Jun 25 01:12:25 2013 (r253466) @@ -25,11 +25,12 @@ #include "pk-backend.h" /* PkGroupEnum, PK_* */ #include "groups.h" /* prototypes */ +#include "mappings.h" /* mapping macros */ const char ORIGIN_SEPARATOR = '/'; struct group_mapping { - const char *dir; + const char *key; PkGroupEnum group; }; @@ -40,7 +41,7 @@ * Some of these mappings are a bit iffy, peer review would be greatly * appreciated. * - * These should ALWAYS be in alphabetical order of ports directories. This is + * These should ALWAYS be in ASCIIbetical order of ports directories. This is * in case anything relies on this property when searching this list (for * example binary searching) */ @@ -122,7 +123,7 @@ PkBitfield bits; bits = 0; - for (i = 0; group_mappings[i].dir != NULL; i++) + for (i = 0; group_mappings[i].key != NULL; i++) pk_bitfield_add(bits, group_mappings[i].group); return bits; @@ -132,13 +133,10 @@ PkGroupEnum group_from_port_dir(const char *port_dir) { - int i; - - i = 0; - while (group_mappings[i].dir != NULL && - g_strcmp0(group_mappings[i].dir, port_dir) != 0) - i++; - return group_mappings[i].group; + struct group_mapping *result; + + MAPPING_FIND(port_dir, &result, group_mappings); + return result->group; } /* Maps from package origins to PackageKit groups. */ Added: soc2013/mattbw/backend/licenses.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/licenses.c Tue Jun 25 01:12:25 2013 (r253466) @@ -0,0 +1,92 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pkg.h" /* struct pkg, etc */ +#include "pk-backend.h" /* PkLicenseEnum, PK_* */ + +#include "licenses.h" /* prototypes */ +#include "mappings.h" /* mapping macros */ + +static const char * license_name_from_pkg(struct pkg *pkg); + +struct license_mapping { + const char *key; + PkLicenseEnum license; +}; + +/* + * Mappings between the output of "pkg_license_name" and the closest available + * PackageKit license. + * + * These should ALWAYS be in ASCIIbetical order of license names. This is in + * case anything relies on this property when searching the list (for example + * binary searching). + */ +static struct license_mapping license_mappings[] = { + {"BSD", PK_LICENSE_ENUM_BSD}, + {NULL, PK_LICENSE_ENUM_UNKNOWN} +}; + +/* Returns the closest approximation packagekit has to this package's license. + * + * PackageKit only has a simple concept of licencing, so this is inherently a + * very lossy mapping. + */ +PkLicenseEnum +license_from_pkg(struct pkg *pkg) +{ + const char *pkg_license_name; + struct license_mapping *map; + PkLicenseEnum result; + + pkg_license_name = license_name_from_pkg(pkg); + + /* Is it in our manual license mapping? + * If not, then try interpreting it as a PackageKit license name and + * convert it back (messy, but hopefully safe), but only if it isn't + * NULL. + */ + MAPPING_FIND(pkg_license_name, &map, license_mappings); + if (pkg_license_name != NULL && map->key == NULL) + result = pk_license_enum_from_string(pkg_license_name); + else + result = map->license; + + return result; +} + +/* Retrieves the name of the FIRST license attached to the package. */ +static const char * +license_name_from_pkg(struct pkg *pkg) +{ + int err; + const char *match; + struct pkg_license *lic; + + lic = NULL; + match = NULL; + do { + err = pkg_licenses(pkg, &lic); + if (err == EPKG_OK) + match = pkg_license_name(lic); + } while (err == EPKG_OK && match == NULL); + + return match; +} Added: soc2013/mattbw/backend/licenses.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/licenses.h Tue Jun 25 01:12:25 2013 (r253466) @@ -0,0 +1,28 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_LICENSES_H_ +#define _PKGNG_BACKEND_LICENSES_H_ + +#include "pk-backend.h" + +PkLicenseEnum license_from_pkg(struct pkg *pkg); + +#endif /* _PKGNG_BACKEND_LICENSES_H_ */ Added: soc2013/mattbw/backend/mappings.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/mappings.h Tue Jun 25 01:12:25 2013 (r253466) @@ -0,0 +1,39 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* Macros for dealing with string-key-to-enum-value mapping lists. */ + +#include "glib.h" /* g_strcmp0 */ + +/* + * Finds a mapping entry given its string key "sk", and sets the pointer + * pointed to by "vp" to reference it. Expects the last (fallthrough) entry + * to have a string value of NULL, will point to it if no other match was + * found. + * + * Currently a linear search, could be improved. Any way to make this not a + * horrible macro would also be welcomed (it's a macro to make it work across + * different types of mapping, at the moment). + */ +#define MAPPING_FIND(sk, vp, map) do { \ + for (*(vp) = map; \ + (*(vp))->key != NULL && g_strcmp0((*(vp))->key, (sk)) != 0;\ + (*(vp)) += 1); \ +} while(0) From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 01:20:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3DDA594D for ; Tue, 25 Jun 2013 01:20:36 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 2179C1A19 for ; Tue, 25 Jun 2013 01:20:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P1KasR062481 for ; Tue, 25 Jun 2013 01:20:36 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P1KaAf062451 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 01:20:36 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 01:20:36 GMT Message-Id: <201306250120.r5P1KaAf062451@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253467 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 01:20:36 -0000 Author: mattbw Date: Tue Jun 25 01:20:35 2013 New Revision: 253467 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253467 Log: hook up get-details to licence NAME getter (for some reason get-details wants name and not enum, may need to ask about this...). Modified: soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/licenses.c soc2013/mattbw/backend/licenses.h Modified: soc2013/mattbw/backend/get-details.c ============================================================================== --- soc2013/mattbw/backend/get-details.c Tue Jun 25 01:12:25 2013 (r253466) +++ soc2013/mattbw/backend/get-details.c Tue Jun 25 01:20:35 2013 (r253467) @@ -25,8 +25,11 @@ #include "pkg.h" #include "db.h" /* open_remote_db */ -#include "groups.h" /* group_from_origin */ #include "get-details.h" /* get_details_thread prototype */ +#include "groups.h" /* group_from_origin */ +#include "licenses.h" /* license_from_pkg */ + +static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; /* TODO: move out of get-details? */ const char *null_if_empty(const char *in); @@ -88,7 +91,7 @@ found = FALSE; match = NULL; do { - err = pkgdb_it_next(matches, &match, PKG_LOAD_BASIC); + err = pkgdb_it_next(matches, &match, LOAD_FLAGS); if (err == EPKG_OK) { const char *arch; const char *data; @@ -140,7 +143,7 @@ /* TODO: implement category, size and licence */ pk_backend_details(backend, new_id, - NULL, + license_name_from_pkg(match), group_from_origin(origin), description, www, Modified: soc2013/mattbw/backend/licenses.c ============================================================================== --- soc2013/mattbw/backend/licenses.c Tue Jun 25 01:12:25 2013 (r253466) +++ soc2013/mattbw/backend/licenses.c Tue Jun 25 01:20:35 2013 (r253467) @@ -18,13 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "pkg.h" /* struct pkg, etc */ -#include "pk-backend.h" /* PkLicenseEnum, PK_* */ +#include "pkg.h" /* struct pkg, etc */ +#include "pk-backend.h" /* PkLicenseEnum, PK_* */ -#include "licenses.h" /* prototypes */ -#include "mappings.h" /* mapping macros */ - -static const char * license_name_from_pkg(struct pkg *pkg); +#include "licenses.h" /* prototypes */ +#include "mappings.h" /* mapping macros */ struct license_mapping { const char *key; @@ -32,9 +30,9 @@ }; /* - * Mappings between the output of "pkg_license_name" and the closest available - * PackageKit license. - * + * Mappings between the output of "pkg_license_name" and the closest + * available PackageKit license. + * * These should ALWAYS be in ASCIIbetical order of license names. This is in * case anything relies on this property when searching the list (for example * binary searching). @@ -44,24 +42,26 @@ {NULL, PK_LICENSE_ENUM_UNKNOWN} }; -/* Returns the closest approximation packagekit has to this package's license. - * +/* + * Returns the closest approximation packagekit has to this package's + * license. + * * PackageKit only has a simple concept of licencing, so this is inherently a * very lossy mapping. */ PkLicenseEnum license_from_pkg(struct pkg *pkg) { - const char *pkg_license_name; + const char *pkg_license_name; struct license_mapping *map; - PkLicenseEnum result; + PkLicenseEnum result; pkg_license_name = license_name_from_pkg(pkg); - /* Is it in our manual license mapping? - * If not, then try interpreting it as a PackageKit license name and - * convert it back (messy, but hopefully safe), but only if it isn't - * NULL. + /* + * Is it in our manual license mapping? If not, then try interpreting + * it as a PackageKit license name and convert it back (messy, but + * hopefully safe), but only if it isn't NULL. */ MAPPING_FIND(pkg_license_name, &map, license_mappings); if (pkg_license_name != NULL && map->key == NULL) @@ -73,11 +73,11 @@ } /* Retrieves the name of the FIRST license attached to the package. */ -static const char * +const char * license_name_from_pkg(struct pkg *pkg) { - int err; - const char *match; + int err; + const char *match; struct pkg_license *lic; lic = NULL; Modified: soc2013/mattbw/backend/licenses.h ============================================================================== --- soc2013/mattbw/backend/licenses.h Tue Jun 25 01:12:25 2013 (r253466) +++ soc2013/mattbw/backend/licenses.h Tue Jun 25 01:20:35 2013 (r253467) @@ -24,5 +24,6 @@ #include "pk-backend.h" PkLicenseEnum license_from_pkg(struct pkg *pkg); +const char *license_name_from_pkg(struct pkg *pkg); #endif /* _PKGNG_BACKEND_LICENSES_H_ */ From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 03:54:59 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id BF98378A for ; Tue, 25 Jun 2013 03:54:59 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id A232D10EA for ; Tue, 25 Jun 2013 03:54:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P3sxoF086791 for ; Tue, 25 Jun 2013 03:54:59 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P3sxOp086772 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 03:54:59 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 03:54:59 GMT Message-Id: <201306250354.r5P3sxOp086772@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253472 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 03:54:59 -0000 Author: mattbw Date: Tue Jun 25 03:54:59 2013 New Revision: 253472 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253472 Log: restructuring; also fix bug with get-details reporting same package information for different packageIDs Added: soc2013/mattbw/backend/actions/ soc2013/mattbw/backend/actions/get-details.c - copied, changed from r253467, soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/actions/get-details.h - copied, changed from r253439, soc2013/mattbw/backend/get-details.h Deleted: soc2013/mattbw/backend/get-details.c soc2013/mattbw/backend/get-details.h soc2013/mattbw/backend/get_details.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Tue Jun 25 02:48:36 2013 (r253471) +++ soc2013/mattbw/backend/Makefile Tue Jun 25 03:54:59 2013 (r253472) @@ -2,7 +2,8 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c get-details.c groups.c db.c licenses.c +SRCS= pk-backend-pkgng.c groups.c db.c licenses.c +SRCS+= actions/get-details.c LIBDIR= /usr/local/lib/packagekit-backend Copied and modified: soc2013/mattbw/backend/actions/get-details.c (from r253467, soc2013/mattbw/backend/get-details.c) ============================================================================== --- soc2013/mattbw/backend/get-details.c Tue Jun 25 01:20:35 2013 (r253467, copy source) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 03:54:59 2013 (r253472) @@ -21,13 +21,14 @@ #include #include -#include "pk-backend.h" +#include "../pk-backend.h" #include "pkg.h" -#include "db.h" /* open_remote_db */ +#include "../db.h" /* open_remote_db */ +#include "../groups.h" /* group_from_origin */ +#include "../licenses.h" /* license_from_pkg */ + #include "get-details.h" /* get_details_thread prototype */ -#include "groups.h" /* group_from_origin */ -#include "licenses.h" /* license_from_pkg */ static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; @@ -293,7 +294,7 @@ pk_backend_set_percentage(backend, 0); for (i = 0; i < len && no_error_yet; i++) { - no_error_yet = get_details_for(package_ids[0], backend, db); + no_error_yet = get_details_for(package_ids[i], backend, db); pk_backend_set_percentage(backend, ((i * 100) / len)); } pkgdb_close(db); Copied and modified: soc2013/mattbw/backend/actions/get-details.h (from r253439, soc2013/mattbw/backend/get-details.h) ============================================================================== --- soc2013/mattbw/backend/get-details.h Mon Jun 24 19:45:46 2013 (r253439, copy source) +++ soc2013/mattbw/backend/actions/get-details.h Tue Jun 25 03:54:59 2013 (r253472) @@ -22,7 +22,7 @@ #define _PKGNG_BACKEND_GET_DETAILS_H_ #include /* gboolean */ -#include "pk-backend.h" /* PkBackend */ +#include "../pk-backend.h" /* PkBackend */ gboolean get_details_thread(PkBackend *backend); Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jun 25 02:48:36 2013 (r253471) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jun 25 03:54:59 2013 (r253472) @@ -30,8 +30,8 @@ #include "pk-backend.h" #include "pkg.h" -#include "groups.h" /* available_groups */ -#include "get-details.h" /* get_details_thread */ +#include "groups.h" /* available_groups */ +#include "actions/get-details.h"/* get_details_thread */ #define INTENTIONALLY_IGNORE(x) (void)(x) @@ -88,7 +88,7 @@ /* * Return all groups available from this backend. - * + * * The business end of this function is in "groups.c". */ PkBitfield @@ -186,7 +186,8 @@ void pk_backend_get_details(PkBackend *backend, gchar **package_ids) { - INTENTIONALLY_IGNORE(package_ids); /* can be retrieved from backend */ + INTENTIONALLY_IGNORE(package_ids); /* can be retrieved from + * backend */ pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 04:51:41 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id DD319134 for ; Tue, 25 Jun 2013 04:51:41 +0000 (UTC) (envelope-from def@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id CDDB21229 for ; Tue, 25 Jun 2013 04:51:41 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P4pfbL047092 for ; Tue, 25 Jun 2013 04:51:41 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P4pf6W047072 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 04:51:41 GMT (envelope-from def@FreeBSD.org) Date: Tue, 25 Jun 2013 04:51:41 GMT Message-Id: <201306250451.r5P4pf6W047072@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253474 - in soc2013/def: . crashdump-head/sbin/savecore crashdump-head/sys/kern crashdump-head/sys/sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 04:51:41 -0000 Author: def Date: Tue Jun 25 04:51:41 2013 New Revision: 253474 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253474 Log: Extend kerneldumpheader and dumperinfo to use Rijndael. Read new values in savecore. Modified: soc2013/def/ (props changed) soc2013/def/crashdump-head/sbin/savecore/Makefile soc2013/def/crashdump-head/sbin/savecore/savecore.c soc2013/def/crashdump-head/sys/kern/kern_shutdown.c soc2013/def/crashdump-head/sys/sys/conf.h soc2013/def/crashdump-head/sys/sys/kerneldump.h Modified: soc2013/def/crashdump-head/sbin/savecore/Makefile ============================================================================== --- soc2013/def/crashdump-head/sbin/savecore/Makefile Tue Jun 25 03:57:27 2013 (r253473) +++ soc2013/def/crashdump-head/sbin/savecore/Makefile Tue Jun 25 04:51:41 2013 (r253474) @@ -4,5 +4,6 @@ DPADD= ${LIBZ} LDADD= -lz MAN= savecore.8 +CFLAGS+=-I/home/def/soc13/vm/usr/include .include Modified: soc2013/def/crashdump-head/sbin/savecore/savecore.c ============================================================================== --- soc2013/def/crashdump-head/sbin/savecore/savecore.c Tue Jun 25 03:57:27 2013 (r253473) +++ soc2013/def/crashdump-head/sbin/savecore/savecore.c Tue Jun 25 04:51:41 2013 (r253474) @@ -121,6 +121,7 @@ fprintf(f, " Panic String: %s\n", h->panicstring); fprintf(f, " Dump Parity: %u\n", h->parity); fprintf(f, " Bounds: %d\n", bounds); + fprintf(f, " Key length: %d bits\n", h->keyLen); switch(status) { case STATUS_BAD: Modified: soc2013/def/crashdump-head/sys/kern/kern_shutdown.c ============================================================================== --- soc2013/def/crashdump-head/sys/kern/kern_shutdown.c Tue Jun 25 03:57:27 2013 (r253473) +++ soc2013/def/crashdump-head/sys/kern/kern_shutdown.c Tue Jun 25 04:51:41 2013 (r253474) @@ -86,6 +86,8 @@ #include +#include + #ifndef PANIC_REBOOT_WAIT_TIME #define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */ #endif @@ -143,6 +145,8 @@ int dumping; /* system is dumping */ int rebooting; /* system is rebooting */ static struct dumperinfo dumper; /* our selected dumper */ +keyInstance dumper_key; +cipherInstance dumper_cipher; /* Context information for dump-debuggers. */ static struct pcb dumppcb; /* Registers. */ @@ -847,6 +851,11 @@ if (dumper.dumper != NULL) return (EBUSY); dumper = *di; + + dumper.key = &dumper_key; + dumper.cipher = &dumper_cipher; + kerneldump_crypto_init(&dumper); + wantcopy = strlcpy(dumpdevname, devname, sizeof(dumpdevname)); if (wantcopy >= sizeof(dumpdevname)) { printf("set_dumper: device name truncated from '%s' -> '%s'\n", @@ -873,6 +882,19 @@ } void +kerneldump_crypto_init(struct dumperinfo *di) +{ + char keyMaterial[KERNELDUMP_MAX_KEY_SIZE >> 3]; + int i; + + for (i = 0 ; i < KERNELDUMP_MAX_KEY_SIZE >> 3 ; i++) + keyMaterial[i] = i; + + rijndael_makeKey(di->key, DIR_ENCRYPT, KERNELDUMP_MAX_KEY_SIZE, keyMaterial); + rijndael_cipherInit(di->cipher, MODE_ECB, NULL); +} + +void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, uint64_t dumplen, uint32_t blksz) { @@ -889,5 +911,9 @@ strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); if (panicstr != NULL) strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); + kdh->keyLen = dumper_key.keyLen; + strncpy(kdh->keyMaterial, dumper_key.keyMaterial, kdh->keyLen); + kdh->mode = dumper_cipher.mode; + strncpy(kdh->IV, dumper_cipher.IV, KERNELDUMP_MAX_IV_SIZE); kdh->parity = kerneldump_parity(kdh); } Modified: soc2013/def/crashdump-head/sys/sys/conf.h ============================================================================== --- soc2013/def/crashdump-head/sys/sys/conf.h Tue Jun 25 03:57:27 2013 (r253473) +++ soc2013/def/crashdump-head/sys/sys/conf.h Tue Jun 25 04:51:41 2013 (r253474) @@ -331,6 +331,8 @@ u_int maxiosize; /* Max size allowed for an individual I/O */ off_t mediaoffset; /* Initial offset in bytes. */ off_t mediasize; /* Space available in bytes. */ + void *key; /* Key information. */ + void *cipher; /* Cipher information. */ }; int set_dumper(struct dumperinfo *, const char *_devname); Modified: soc2013/def/crashdump-head/sys/sys/kerneldump.h ============================================================================== --- soc2013/def/crashdump-head/sys/sys/kerneldump.h Tue Jun 25 03:57:27 2013 (r253473) +++ soc2013/def/crashdump-head/sys/sys/kerneldump.h Tue Jun 25 04:51:41 2013 (r253474) @@ -75,12 +75,18 @@ #define KERNELDUMP_POWERPC_VERSION 1 #define KERNELDUMP_SPARC64_VERSION 1 #define KERNELDUMP_TEXT_VERSION 1 +#define KERNELDUMP_MAX_KEY_SIZE 256 +#define KERNELDUMP_MAX_IV_SIZE 128 uint64_t dumplength; /* excl headers */ uint64_t dumptime; uint32_t blocksize; char hostname[64]; - char versionstring[192]; - char panicstring[192]; + char versionstring[164]; + char panicstring[164]; + int keyLen; + char keyMaterial[KERNELDUMP_MAX_KEY_SIZE >> 3]; + u_int8_t mode; + u_int8_t IV[KERNELDUMP_MAX_IV_SIZE >> 3]; uint32_t parity; }; @@ -101,6 +107,8 @@ } #ifdef _KERNEL +void kerneldump_crypto_init(struct dumperinfo *di); + void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, uint64_t dumplen, uint32_t blksz); #endif From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 05:47:16 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 80280B8F for ; Tue, 25 Jun 2013 05:47:16 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 7162F1386 for ; Tue, 25 Jun 2013 05:47:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P5lGQI032115 for ; Tue, 25 Jun 2013 05:47:16 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P5lGwG032110 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 05:47:16 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 05:47:16 GMT Message-Id: <201306250547.r5P5lGwG032110@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253477 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 05:47:16 -0000 Author: mattbw Date: Tue Jun 25 05:47:16 2013 New Revision: 253477 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253477 Log: make generic package iterator handler ready for other get-xyz jobs. Added: soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/iterate.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get-details.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Tue Jun 25 04:44:42 2013 (r253476) +++ soc2013/mattbw/backend/Makefile Tue Jun 25 05:47:16 2013 (r253477) @@ -2,7 +2,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c groups.c db.c licenses.c +SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c SRCS+= actions/get-details.c LIBDIR= /usr/local/lib/packagekit-backend Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 04:44:42 2013 (r253476) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 05:47:16 2013 (r253477) @@ -19,13 +19,13 @@ */ #include - #include #include "../pk-backend.h" #include "pkg.h" #include "../db.h" /* open_remote_db */ #include "../groups.h" /* group_from_origin */ +#include "../iterate.h" /* Package iteration */ #include "../licenses.h" /* license_from_pkg */ #include "get-details.h" /* get_details_thread prototype */ @@ -34,7 +34,7 @@ /* TODO: move out of get-details? */ const char *null_if_empty(const char *in); -gboolean string_match(const char *left, const char *right); + static gboolean get_details_query(const gchar *name, const gchar *version, @@ -56,107 +56,32 @@ /* - * Checks two strings with strcmp and emits TRUE if they match. If either - * string is NULL, emit TRUE as well (this is so that missing PackageID - * elements trigger matches). + * Emits the given package's details. To be used as an iterating function. */ -gboolean -string_match(const char *left, const char *right) -{ - int result; - - if (left == NULL || right == NULL) - result = TRUE; - else - result = (strcmp(left, right) == 0 ? TRUE : FALSE); - - return result; -} - -/* - * Go through a database iterator of possible package matches and emit any - * that match the split PackageID. - */ -gboolean -get_details_check_matches(struct pkgdb_it *matches, - const gchar *id_name, - const gchar *id_version, - const gchar *id_arch, - const gchar *id_data, - PkBackend *backend) -{ - gboolean found; - int err; - struct pkg *match; - - found = FALSE; - match = NULL; - do { - err = pkgdb_it_next(matches, &match, LOAD_FLAGS); - if (err == EPKG_OK) { - const char *arch; - const char *data; - const char *description; - const char *name; - const char *origin; - const char *reponame; - const char *version; - const char *www; - int64_t flatsize; - - pkg_get(match, - PKG_ARCH, &arch, - PKG_DESC, &description, - PKG_FLATSIZE, &flatsize, - PKG_NAME, &name, - PKG_ORIGIN, &origin, - PKG_REPONAME, &reponame, - PKG_VERSION, &version, - PKG_WWW, &www); - - switch (pkg_type(match)) { - case PKG_FILE: - data = "local"; - break; - case PKG_INSTALLED: - data = "installed"; - break; - default: - data = reponame; - break; - } - - /* - * Emit if this package's PackageID fields match the - * original PackageID. Of course, the original ID - * might have missing fields (NULLs), so we treat a - * comparison involving one as a success. - */ - if (string_match(name, id_name) && - string_match(version, id_version) && - string_match(arch, id_arch) && - string_match(data, id_data)) { - gchar *new_id; - - found = TRUE; - new_id = pk_package_id_build(name, version, arch, data); - - /* TODO: implement category, size and licence */ - pk_backend_details(backend, - new_id, - license_name_from_pkg(match), - group_from_origin(origin), - description, - www, - flatsize); - - g_free(new_id); - } - } - } while (err == EPKG_OK && found == FALSE); - pkg_free(match); - - return found; +static void +emit_get_details(struct pkg *pkg, + const gchar *id, + PkBackend *backend) +{ + const char *description; + const char *origin; + const char *www; + int64_t flatsize; + + /* Information not already part of the PackageID */ + pkg_get(pkg, + PKG_DESC, &description, + PKG_FLATSIZE, &flatsize, + PKG_ORIGIN, &origin, + PKG_WWW, &www); + + pk_backend_details(backend, + id, + license_name_from_pkg(pkg), + group_from_origin(origin), + description, + www, + flatsize); } /* @@ -186,12 +111,14 @@ else it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); if (it) - success = get_details_check_matches(it, - name, - version, - arch, - reponame, - backend); + success = iterate_id_matches(it, + backend, + name, + version, + arch, + reponame, + LOAD_FLAGS, + emit_get_details); return success; } Added: soc2013/mattbw/backend/iterate.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/iterate.c Tue Jun 25 05:47:16 2013 (r253477) @@ -0,0 +1,132 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include "pk-backend.h" +#include "pkg.h" + +#include "iterate.h" /* Prototypes */ + +static gboolean +try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const + gchar *arch, const gchar *data, gchar **match_id); + +static gboolean string_match(const char *left, const char *right); + +gboolean +iterate_id_matches(struct pkgdb_it *iterator, + PkBackend *backend, + const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *data, + int fetch_flags, + iterate_f_pointer iterate_f) +{ + /* TODO: Filters */ + gboolean found; + int err; + struct pkg *pkg; + gchar *match_id; + + found = FALSE; + pkg = NULL; + match_id = NULL; + do { + err = pkgdb_it_next(iterator, &pkg, fetch_flags); + + if (err == EPKG_OK && try_id_match(pkg, + name, + version, + arch, + data, + &match_id) == TRUE) { + found = TRUE; + iterate_f(pkg, match_id, backend); + } + if (match_id != NULL) + g_free(match_id); + } while (err == EPKG_OK && found == FALSE); + pkg_free(pkg); + + return found; +} + +static gboolean +try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const + gchar *arch, const gchar *data, gchar **match_id) +{ + const char *pkg_arch; + const char *pkg_data; + const char *pkg_name; + const char *pkg_reponame; + const char *pkg_version; + + pkg_get(pkg, + PKG_ARCH, &pkg_arch, + PKG_NAME, &pkg_name, + PKG_REPONAME, &pkg_reponame, + PKG_VERSION, &pkg_version); + + switch (pkg_type(pkg)) { + case PKG_FILE: + pkg_data = "local"; + break; + case PKG_INSTALLED: + pkg_data = "installed"; + break; + default: + pkg_data = pkg_reponame; + break; + } + + if (*match_id != NULL) + g_free(*match_id); + *match_id = pk_package_id_build(pkg_name, pkg_version, pkg_arch, pkg_data); + + /* + * Succeed if this package's PackageID fields match the original + * PackageID. Of course, the original ID might have missing fields + * (NULLs), so we treat a comparison involving one as a success. + */ + return (string_match(name, pkg_name) && + string_match(version, pkg_version) && + string_match(arch, pkg_arch) && + string_match(data, pkg_data)) ? TRUE : FALSE; +} + +/* + * Checks two strings with strcmp and emits TRUE if they match. If either + * string is NULL, emit TRUE as well (this is so that missing PackageID + * elements trigger matches). + */ +static gboolean +string_match(const char *left, const char *right) +{ + int result; + + if (left == NULL || right == NULL) + result = TRUE; + else + result = (strcmp(left, right) == 0 ? TRUE : FALSE); + + return result; +} Added: soc2013/mattbw/backend/iterate.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/iterate.h Tue Jun 25 05:47:16 2013 (r253477) @@ -0,0 +1,42 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_ITERATE_H_ +#define _PKGNG_BACKEND_ITERATE_H_ + +#include +#include "pk-backend.h" +#include "pkg.h" + +typedef void (*iterate_f_pointer) (struct pkg *pkg, + const char *id, + PkBackend *backend); + +gboolean +iterate_id_matches(struct pkgdb_it *iterator, + PkBackend *backend, + const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *data, + int fetch_flags, + iterate_f_pointer iterate_f); + +#endif /* !_PKGNG_BACKEND_ITERATE_H_ */ From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 06:34:44 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0D1492A9 for ; Tue, 25 Jun 2013 06:34:44 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id D9F79166F for ; Tue, 25 Jun 2013 06:34:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P6YhNv082977 for ; Tue, 25 Jun 2013 06:34:43 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P6YhSB082971 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 06:34:43 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 25 Jun 2013 06:34:43 GMT Message-Id: <201306250634.r5P6YhSB082971@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253479 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 06:34:44 -0000 Author: dpl Date: Tue Jun 25 06:34:43 2013 New Revision: 253479 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253479 Log: Added error checking. Getting weird fd from socket. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 05:05:10 2013 (r253478) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 06:34:43 2013 (r253479) @@ -1365,23 +1365,40 @@ pad ( inName ); fflush ( stderr ); } + printf("About to fork!\n"); # if CAPSICUM /* Pass the limited file descriptors with a unix domain socket. */ - switch( forkpid = rfork(RFPROC | RFCFDG) ) { + switch( forkpid = fork() ) { case ( 0 ): - if (fd == recvfd(sv[1]) <= 0){ - fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", + printf("Child\n"); + if(fclose(inStr) < 0){ + fprintf ( stderr, "%s: Couldn't close inStr: %s.\n", progName, strerror(errno) ); - exit(1); + setExit(1); + exit(exitValue); + } + if(fclose(outStr) < 0){ + fprintf ( stderr, "%s: Couldn't close outStr: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + printf("closed fds\n"); + if (fd == recvfd(sv[1]) <= 0){ + fprintf ( stderr, "%s: Couldn't get inStr(%d) fd: %s.\n", + progName, fd, strerror(errno) ); + setExit(1); + exit(exitValue); } printf("inStr fd receiverd: %d\n",fd); inStr = fdopen(fd, "rb"); if (fd == recvfd(sv[1]) <= 0){ - fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", - progName, strerror(errno) ); - exit(1); + fprintf ( stderr, "%s: Couldn't get outStr(%d) fd: %s.\n", + progName, fd, strerror(errno) ); + setExit(1); + exit(exitValue); } outStr = fdopen(fd, "wb"); printf("outStr fd receiverd: %d\n",fd); @@ -1389,7 +1406,8 @@ if (cap_enter() < 0) { fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", progName, strerror(errno) ); - exit(1); + setExit(1); + exit(exitValue); } # endif @@ -1416,9 +1434,12 @@ case ( -1 ): fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) ); - exit(1); + setExit(1); + exit(exitValue); default: + printf("Parent.\n"); + printf("Waiting for son.\n"); fd = fileno(inStr); cap_rights_limit(fd, CAP_READ); sendfd(sv[0], fd); From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 08:26:12 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C647ADD4 for ; Tue, 25 Jun 2013 08:26:12 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id A92821A83 for ; Tue, 25 Jun 2013 08:26:12 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5P8QCoD021441 for ; Tue, 25 Jun 2013 08:26:12 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5P8QCgo021439 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 08:26:12 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 25 Jun 2013 08:26:12 GMT Message-Id: <201306250826.r5P8QCgo021439@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253487 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 08:26:12 -0000 Author: dpl Date: Tue Jun 25 08:26:12 2013 New Revision: 253487 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253487 Log: Close FILE * streams before forking and limit its fds capabilities. Getting an error with fileno(). Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 07:32:49 2013 (r253486) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 08:26:12 2013 (r253487) @@ -1209,7 +1209,7 @@ FILE *outStr; Int32 n, i; # if CAPSICUM - Int32 fd; + Int32 infd, outfd; pid_t forkpid; # endif struct MY_STAT statBuf; @@ -1365,43 +1365,52 @@ pad ( inName ); fflush ( stderr ); } - printf("About to fork!\n"); # if CAPSICUM + fprintf(stderr,"infd: %d\n", fileno(inStr)); + infd = fileno(inStr); + fprintf(stderr,"infd: %d\n", infd); + outfd = fileno(outStr); + fprintf(stderr,"outfd: %d\n", outfd); + /*cap_rights_limit(infd, CAP_READ);*/ + /*cap_rights_limit(outfd, CAP_WRITE);*/ + + if(fclose(inStr) < 0){ + fprintf ( stderr, "%s: Couldn't close inStr: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + if(fclose(outStr) < 0){ + fprintf ( stderr, "%s: Couldn't close outStr: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + + printf("About to fork()"); /* Pass the limited file descriptors with a unix domain socket. */ switch( forkpid = fork() ) { case ( 0 ): + sleep(1); printf("Child\n"); - if(fclose(inStr) < 0){ - fprintf ( stderr, "%s: Couldn't close inStr: %s.\n", - progName, strerror(errno) ); - setExit(1); - exit(exitValue); - } - if(fclose(outStr) < 0){ - fprintf ( stderr, "%s: Couldn't close outStr: %s.\n", - progName, strerror(errno) ); - setExit(1); - exit(exitValue); - } - printf("closed fds\n"); - if (fd == recvfd(sv[1]) <= 0){ - fprintf ( stderr, "%s: Couldn't get inStr(%d) fd: %s.\n", - progName, fd, strerror(errno) ); - setExit(1); - exit(exitValue); + if ((infd = recvfd(sv[1])) <= 0){ + fprintf ( stderr, "%s: Couldn't get fd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); } - printf("inStr fd receiverd: %d\n",fd); - inStr = fdopen(fd, "rb"); + printf("inStr fd received: %d\n",infd); + inStr = fdopen(infd, "rb"); - if (fd == recvfd(sv[1]) <= 0){ - fprintf ( stderr, "%s: Couldn't get outStr(%d) fd: %s.\n", - progName, fd, strerror(errno) ); - setExit(1); - exit(exitValue); + if ((outfd = recvfd(sv[1])) <= 0){ + fprintf ( stderr, "%s: Couldn't get fd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); } - outStr = fdopen(fd, "wb"); - printf("outStr fd receiverd: %d\n",fd); + printf("outStr fd received: %d\n",outfd); + outStr = fdopen(outfd, "wb"); if (cap_enter() < 0) { fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", @@ -1428,6 +1437,7 @@ } deleteOutputOnInterrupt = False; + exit(0); # if CAPSICUM break; @@ -1438,17 +1448,10 @@ exit(exitValue); default: - printf("Parent.\n"); - printf("Waiting for son.\n"); - fd = fileno(inStr); - cap_rights_limit(fd, CAP_READ); - sendfd(sv[0], fd); - printf("Sending inStr fd: %d\n", fd); - fd = fileno(outStr); - cap_rights_limit(fd, CAP_WRITE); - sendfd(sv[0], fd); - printf("Sending outStr fd: %d\n", fd); - wait(NULL); + sendfd(sv[0], infd); + sendfd(sv[0], outfd); + printf("Waiting\n"); + wait(0); return; } # endif From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 19:14:42 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A46354F2 for ; Tue, 25 Jun 2013 19:14:42 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 8655F1EF8 for ; Tue, 25 Jun 2013 19:14:42 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PJEfgQ053177 for ; Tue, 25 Jun 2013 19:14:41 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5PJEfxQ053175 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 19:14:41 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 25 Jun 2013 19:14:41 GMT Message-Id: <201306251914.r5PJEfxQ053175@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253495 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 19:14:42 -0000 Author: dpl Date: Tue Jun 25 19:14:41 2013 New Revision: 253495 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253495 Log: Rewrite socketpair(), and open correctly the files (only compressing). Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 18:44:15 2013 (r253494) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 19:14:41 2013 (r253495) @@ -221,7 +221,7 @@ FILE *outputHandleJustInCase; Int32 workFactor; -#if CAPSICUM == 1 +#if CAPSICUM int sv[2], len; int sendfd(int, int); @@ -1316,6 +1316,7 @@ break; case SM_F2O: + inStr = fopen ( inName, "rb" ); outStr = stdout; if ( isatty ( fileno ( stdout ) ) ) { fprintf ( stderr, @@ -1323,7 +1324,6 @@ progName ); fprintf ( stderr, "%s: For help, type: `%s --help'.\n", progName, progName ); - inStr = fopen ( inName, "rb" ); if ( inStr != NULL ) fclose ( inStr ); setExit(1); return; @@ -1337,11 +1337,11 @@ break; case SM_F2F: + inStr = fopen ( inName, "rb" ); outStr = fopen_output_safely ( outName, "wb" ); if ( outStr == NULL) { fprintf ( stderr, "%s: Can't create output file %s: %s.\n", progName, outName, strerror(errno) ); - inStr = fopen ( inName, "rb" ); if ( inStr != NULL ) fclose ( inStr ); setExit(1); return; @@ -1367,13 +1367,10 @@ } # if CAPSICUM - fprintf(stderr,"infd: %d\n", fileno(inStr)); infd = fileno(inStr); - fprintf(stderr,"infd: %d\n", infd); outfd = fileno(outStr); - fprintf(stderr,"outfd: %d\n", outfd); - /*cap_rights_limit(infd, CAP_READ);*/ - /*cap_rights_limit(outfd, CAP_WRITE);*/ + cap_rights_limit(infd, CAP_READ); + cap_rights_limit(outfd, CAP_WRITE); if(fclose(inStr) < 0){ fprintf ( stderr, "%s: Couldn't close inStr: %s.\n", @@ -1388,14 +1385,18 @@ exit(exitValue); } - printf("About to fork()"); + printf("About to fork()\n"); /* Pass the limited file descriptors with a unix domain socket. */ switch( forkpid = fork() ) { + case ( -1 ): + fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) ); + setExit(1); + exit(exitValue); + case ( 0 ): - sleep(1); printf("Child\n"); if ((infd = recvfd(sv[1])) <= 0){ - fprintf ( stderr, "%s: Couldn't get fd: %s.\n", + fprintf ( stderr, "%s: Couldn't get fd infd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); @@ -1404,7 +1405,7 @@ inStr = fdopen(infd, "rb"); if ((outfd = recvfd(sv[1])) <= 0){ - fprintf ( stderr, "%s: Couldn't get fd: %s.\n", + fprintf ( stderr, "%s: Couldn't get fd outfd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); @@ -1442,15 +1443,20 @@ # if CAPSICUM break; - case ( -1 ): - fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) ); - setExit(1); - exit(exitValue); - default: - sendfd(sv[0], infd); - sendfd(sv[0], outfd); - printf("Waiting\n"); + printf("infd:%d, outfd:%d\n", infd, outfd); + if (sendfd(sv[0], infd) < 0){ + fprintf ( stderr, "%s: Couldn't send fd infd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + if (sendfd(sv[0], outfd) < 0){ + fprintf ( stderr, "%s: Couldn't send fd outfd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } wait(0); return; } @@ -2105,6 +2111,17 @@ # endif } +# if CAPSICUM + + if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 ){ + fprintf (stderr, "%s: Can't create socket: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + +# endif + if (opMode == OM_Z) { if (srcMode == SM_I2O) { compress ( NULL ); From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 21:16:01 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C1387607 for ; Tue, 25 Jun 2013 21:16:01 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B05F117C8 for ; Tue, 25 Jun 2013 21:16:01 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PLG1D9083258 for ; Tue, 25 Jun 2013 21:16:01 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5PLG1eQ083243 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 21:16:01 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 21:16:01 GMT Message-Id: <201306252116.r5PLG1eQ083243@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253499 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 21:16:01 -0000 Author: mattbw Date: Tue Jun 25 21:16:01 2013 New Revision: 253499 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253499 Log: random spring cleaning? Modified: soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/licenses.c soc2013/mattbw/backend/licenses.h Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 20:23:08 2013 (r253498) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 21:16:01 2013 (r253499) @@ -46,13 +46,6 @@ get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db); -gboolean -get_details_check_matches(struct pkgdb_it *matches, - const gchar *id_name, - const gchar *id_version, - const gchar *id_arch, - const gchar *id_data, - PkBackend *backend); /* Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Tue Jun 25 20:23:08 2013 (r253498) +++ soc2013/mattbw/backend/iterate.c Tue Jun 25 21:16:01 2013 (r253499) @@ -74,43 +74,43 @@ try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const gchar *arch, const gchar *data, gchar **match_id) { - const char *pkg_arch; - const char *pkg_data; - const char *pkg_name; - const char *pkg_reponame; - const char *pkg_version; + const char *p_arch; + const char *p_data; + const char *p_name; + const char *p_reponame; + const char *p_version; pkg_get(pkg, - PKG_ARCH, &pkg_arch, - PKG_NAME, &pkg_name, - PKG_REPONAME, &pkg_reponame, - PKG_VERSION, &pkg_version); + PKG_ARCH, &p_arch, + PKG_NAME, &p_name, + PKG_REPONAME, &p_reponame, + PKG_VERSION, &p_version); switch (pkg_type(pkg)) { case PKG_FILE: - pkg_data = "local"; + p_data = "local"; break; case PKG_INSTALLED: - pkg_data = "installed"; + p_data = "installed"; break; default: - pkg_data = pkg_reponame; + p_data = p_reponame; break; } if (*match_id != NULL) g_free(*match_id); - *match_id = pk_package_id_build(pkg_name, pkg_version, pkg_arch, pkg_data); + *match_id = pk_package_id_build(p_name, p_version, p_arch, p_data); /* * Succeed if this package's PackageID fields match the original * PackageID. Of course, the original ID might have missing fields * (NULLs), so we treat a comparison involving one as a success. */ - return (string_match(name, pkg_name) && - string_match(version, pkg_version) && - string_match(arch, pkg_arch) && - string_match(data, pkg_data)) ? TRUE : FALSE; + return (string_match(name, p_name) && + string_match(version, p_version) && + string_match(arch, p_arch) && + string_match(data, p_data)) ? TRUE : FALSE; } /* Modified: soc2013/mattbw/backend/licenses.c ============================================================================== --- soc2013/mattbw/backend/licenses.c Tue Jun 25 20:23:08 2013 (r253498) +++ soc2013/mattbw/backend/licenses.c Tue Jun 25 21:16:01 2013 (r253499) @@ -22,60 +22,12 @@ #include "pk-backend.h" /* PkLicenseEnum, PK_* */ #include "licenses.h" /* prototypes */ -#include "mappings.h" /* mapping macros */ - -struct license_mapping { - const char *key; - PkLicenseEnum license; -}; - -/* - * Mappings between the output of "pkg_license_name" and the closest - * available PackageKit license. - * - * These should ALWAYS be in ASCIIbetical order of license names. This is in - * case anything relies on this property when searching the list (for example - * binary searching). - */ -static struct license_mapping license_mappings[] = { - {"BSD", PK_LICENSE_ENUM_BSD}, - {NULL, PK_LICENSE_ENUM_UNKNOWN} -}; - -/* - * Returns the closest approximation packagekit has to this package's - * license. - * - * PackageKit only has a simple concept of licencing, so this is inherently a - * very lossy mapping. - */ -PkLicenseEnum -license_from_pkg(struct pkg *pkg) -{ - const char *pkg_license_name; - struct license_mapping *map; - PkLicenseEnum result; - - pkg_license_name = license_name_from_pkg(pkg); - - /* - * Is it in our manual license mapping? If not, then try interpreting - * it as a PackageKit license name and convert it back (messy, but - * hopefully safe), but only if it isn't NULL. - */ - MAPPING_FIND(pkg_license_name, &map, license_mappings); - if (pkg_license_name != NULL && map->key == NULL) - result = pk_license_enum_from_string(pkg_license_name); - else - result = map->license; - - return result; -} /* Retrieves the name of the FIRST license attached to the package. */ const char * license_name_from_pkg(struct pkg *pkg) { + /* TODO: handle conjunctions and disjunctions */ int err; const char *match; struct pkg_license *lic; Modified: soc2013/mattbw/backend/licenses.h ============================================================================== --- soc2013/mattbw/backend/licenses.h Tue Jun 25 20:23:08 2013 (r253498) +++ soc2013/mattbw/backend/licenses.h Tue Jun 25 21:16:01 2013 (r253499) @@ -23,7 +23,6 @@ #include "pk-backend.h" -PkLicenseEnum license_from_pkg(struct pkg *pkg); const char *license_name_from_pkg(struct pkg *pkg); #endif /* _PKGNG_BACKEND_LICENSES_H_ */ From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 21:40:23 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D5FDCBB5 for ; Tue, 25 Jun 2013 21:40:23 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B76E218C7 for ; Tue, 25 Jun 2013 21:40:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PLeN79010000 for ; Tue, 25 Jun 2013 21:40:23 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5PLeNVa009980 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 21:40:23 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 21:40:23 GMT Message-Id: <201306252140.r5PLeNVa009980@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253500 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 21:40:23 -0000 Author: mattbw Date: Tue Jun 25 21:40:23 2013 New Revision: 253500 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253500 Log: move more iterating boilerplate to iterate Modified: soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/iterate.h Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 21:16:01 2013 (r253499) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 21:40:23 2013 (r253500) @@ -23,7 +23,6 @@ #include "../pk-backend.h" #include "pkg.h" -#include "../db.h" /* open_remote_db */ #include "../groups.h" /* group_from_origin */ #include "../iterate.h" /* Package iteration */ #include "../licenses.h" /* license_from_pkg */ @@ -47,6 +46,15 @@ PkBackend *backend, struct pkgdb *db); +/* + * The thread that performs a GetDetails operation. Should be invoked by the + * pk_backend_get_details hook. + */ +gboolean +get_details_thread(PkBackend *backend) +{ + return iterate_ids(backend, get_details_for); +} /* * Emits the given package's details. To be used as an iterating function. @@ -192,33 +200,4 @@ return success; } -/* - * The thread that performs a GetDetails operation. Should be invoked by the - * pk_backend_get_details hook. - */ -gboolean -get_details_thread(PkBackend *backend) -{ - gboolean no_error_yet; - gchar **package_ids; - guint len; - guint i; - struct pkgdb *db; - - - package_ids = pk_backend_get_strv(backend, "package_ids"); - len = g_strv_length(package_ids); - - db = NULL; - no_error_yet = open_remote_db(&db, backend); - - pk_backend_set_percentage(backend, 0); - for (i = 0; i < len && no_error_yet; i++) { - no_error_yet = get_details_for(package_ids[i], backend, db); - pk_backend_set_percentage(backend, ((i * 100) / len)); - } - pkgdb_close(db); - pk_backend_finished(backend); - return no_error_yet; -} Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Tue Jun 25 21:16:01 2013 (r253499) +++ soc2013/mattbw/backend/iterate.c Tue Jun 25 21:40:23 2013 (r253500) @@ -25,6 +25,8 @@ #include "iterate.h" /* Prototypes */ +#include "db.h" /* open_remote_db */ + static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const gchar *arch, const gchar *data, gchar **match_id); @@ -39,7 +41,7 @@ const gchar *arch, const gchar *data, int fetch_flags, - iterate_f_pointer iterate_f) + pkg_func_ptr iterate_f) { /* TODO: Filters */ gboolean found; @@ -130,3 +132,37 @@ return result; } + +/* Iterates over a set of PackageIDs provided for this job with a function. + * + * This provides each iterating function call with an open database connection + * and updates the percentage after each iteration. + * + * It also *finishes* the backend job. + */ +gboolean +iterate_ids(PkBackend *backend, ids_func_ptr iterate_f) +{ + gboolean no_error_yet; + gchar **package_ids; + guint len; + guint i; + struct pkgdb *db; + + package_ids = pk_backend_get_strv(backend, "package_ids"); + len = g_strv_length(package_ids); + + db = NULL; + no_error_yet = open_remote_db(&db, backend); + + pk_backend_set_percentage(backend, 0); + for (i = 0; i < len && no_error_yet; i++) { + no_error_yet = iterate_f(package_ids[i], backend, db); + pk_backend_set_percentage(backend, ((i * 100) / len)); + } + pkgdb_close(db); + + pk_backend_finished(backend); + + return no_error_yet; +} Modified: soc2013/mattbw/backend/iterate.h ============================================================================== --- soc2013/mattbw/backend/iterate.h Tue Jun 25 21:16:01 2013 (r253499) +++ soc2013/mattbw/backend/iterate.h Tue Jun 25 21:40:23 2013 (r253500) @@ -25,9 +25,10 @@ #include "pk-backend.h" #include "pkg.h" -typedef void (*iterate_f_pointer) (struct pkg *pkg, +typedef void (*pkg_func_ptr) (struct pkg *pkg, const char *id, PkBackend *backend); +typedef gboolean (*ids_func_ptr) (gchar *id, PkBackend *backend, struct pkgdb *db); gboolean iterate_id_matches(struct pkgdb_it *iterator, @@ -37,6 +38,7 @@ const gchar *arch, const gchar *data, int fetch_flags, - iterate_f_pointer iterate_f); + pkg_func_ptr iterate_f); +gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); #endif /* !_PKGNG_BACKEND_ITERATE_H_ */ From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 23:37:18 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6877B68F for ; Tue, 25 Jun 2013 23:37:18 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 57BEB1C82 for ; Tue, 25 Jun 2013 23:37:18 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PNbIeE076551 for ; Tue, 25 Jun 2013 23:37:18 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5PNbIZ0076528 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 23:37:18 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 23:37:18 GMT Message-Id: <201306252337.r5PNbIZ0076528@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253509 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 23:37:18 -0000 Author: mattbw Date: Tue Jun 25 23:37:18 2013 New Revision: 253509 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253509 Log: implemented GetFiles; may not throw the correct error message at the moment for non-installed files. Added: soc2013/mattbw/backend/actions/get-files.c soc2013/mattbw/backend/actions/get-files.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/db.c soc2013/mattbw/backend/db.h soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/Makefile Tue Jun 25 23:37:18 2013 (r253509) @@ -3,7 +3,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c -SRCS+= actions/get-details.c +SRCS+= actions/get-details.c actions/get-files.c LIBDIR= /usr/local/lib/packagekit-backend Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/actions/get-details.c Tue Jun 25 23:37:18 2013 (r253509) @@ -18,11 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include #include #include "../pk-backend.h" #include "pkg.h" +#include "../db.h" /* db_query_from_id */ #include "../groups.h" /* group_from_origin */ #include "../iterate.h" /* Package iteration */ #include "../licenses.h" /* license_from_pkg */ @@ -30,17 +30,7 @@ #include "get-details.h" /* get_details_thread prototype */ static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; - -/* TODO: move out of get-details? */ -const char *null_if_empty(const char *in); - -static gboolean -get_details_query(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db); +static void get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); static gboolean get_details_for(gchar *package_id, PkBackend *backend, @@ -60,9 +50,7 @@ * Emits the given package's details. To be used as an iterating function. */ static void -emit_get_details(struct pkg *pkg, - const gchar *id, - PkBackend *backend) +get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) { const char *description; const char *origin; @@ -86,118 +74,11 @@ } /* - * Looks the split PackageID up in the package databases. - * - * Usually, a remote query will be done on the repository named by "reponame". - * If reponame is NULL, a remote check will be done against all repostories. - * If it is "installed", a local check will be done. (This is in keeping - * with the special meaning of the "installed" repository in PackageIDs). + * Look up and emit package details for the given PackageID, if it can be + * found. */ -static gboolean -get_details_query(const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *reponame, - PkBackend *backend, - struct pkgdb *db) -{ - struct pkgdb_it *it; - gboolean success; - - success = FALSE; - - /* Are we doing a local query? */ - if (g_strcmp0(reponame, "installed") == 0) - it = pkgdb_query(db, name, MATCH_EXACT); - else - it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); - if (it) - success = iterate_id_matches(it, - backend, - name, - version, - arch, - reponame, - LOAD_FLAGS, - emit_get_details); - return success; -} - -/* - * If the input pointer points to a string that is empty, return the null - * pointer; else pass through the pointer unmolested. - * - * This does NOT free anything! - */ -const char * -null_if_empty(const char *in) -{ - return (in != NULL && strlen(in) == 0) ? NULL : in; -} - gboolean get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) { - gchar **parts; - gboolean success; - - success = FALSE; - - parts = pk_package_id_split(package_id); - if (parts == NULL) - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_ID_INVALID, - "invalid package id"); - else { - /* Parts of the package ID */ - const gchar *name; - const gchar *version; - const gchar *arch; - const gchar *data; - - /* - * Make really really REALLY sure that the PackageID fields - * either have sensible data in them, or are NULL. - */ - name = null_if_empty(parts[PK_PACKAGE_ID_NAME]); - version = null_if_empty(parts[PK_PACKAGE_ID_VERSION]); - arch = null_if_empty(parts[PK_PACKAGE_ID_ARCH]); - data = null_if_empty(parts[PK_PACKAGE_ID_DATA]); - - /* - * If the PackageID has a repository specified (even if it's - * "installed" i.e. currently installed package), running - * "get_details_query" directly should handle remote/local - * queries properly. - * - * If there is no repository specified, however (data is NULL), - * we may need to check both the local and (all) remote - * repositories, in that order. (TODO: local packages?) - */ - if (data == NULL) { - /* Try local database first. */ - success = get_details_query(name, - version, - arch, - "installed", - backend, - db); - if (success == FALSE) - success = get_details_query(name, version, NULL, data, backend, db); - } else - success = get_details_query(name, version, arch, data, backend, db); - /* - * Assume any error is due to not finding packages. At time - * of writing this is true, but may change. - */ - if (success == FALSE) - pk_backend_error_code(backend, - PK_ERROR_ENUM_PACKAGE_NOT_FOUND, - "package not found"); - g_strfreev(parts); - } - - return success; + return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_details_emit); } - - Added: soc2013/mattbw/backend/actions/get-files.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get-files.c Tue Jun 25 23:37:18 2013 (r253509) @@ -0,0 +1,102 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more files. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "../pk-backend.h" +#include "pkg.h" + +#include "../db.h" /* db_query_from_id */ +#include "../groups.h" /* group_from_origin */ +#include "../iterate.h" /* Package iteration */ +#include "../licenses.h" /* license_from_pkg */ + +#include "get-files.h" /* get_files_thread prototype */ + +static const int FILE_NAME_STEP = 10; +static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES; + +static void get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); +static gboolean +get_files_for(gchar *package_id, + PkBackend *backend, + struct pkgdb *db); + +/* + * The thread that performs a GetDetails operation. Should be invoked by the + * pk_backend_get_files hook. + */ +gboolean +get_files_thread(PkBackend *backend) +{ + return iterate_ids(backend, get_files_for); +} + +/* + * Emits the given package's files. To be used as an iterating function. + */ +static void +get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) +{ + struct pkg_file *file; + int err; + + gchar **filenames; + gchar *joined_filenames; + gint capacity; + gint i; + + i = 0; + file = NULL; + /* Start off with a small array to hold the file names, + * and expand it if needs be. + */ + capacity = FILE_NAME_STEP; + filenames = g_new(gchar *, capacity); + do { + err = pkg_files(pkg, &file); + if (err == EPKG_OK) { + /* Out of capacity (leaving a NULL)? Expand the array. */ + if (i >= (capacity - 1)) { + capacity += FILE_NAME_STEP; + filenames = g_renew(gchar *, filenames, capacity); + } + + filenames[i] = g_strdup(pkg_file_path(file)); + i++; + } + } while (err == EPKG_OK); + filenames[i] = NULL; + + joined_filenames = g_strjoinv(";", filenames); + g_strfreev(filenames); + + pk_backend_files(backend, id, joined_filenames); + g_free(joined_filenames); +} + +/* + * Look up and emit package files for the given PackageID, if it can be + * found. + */ +gboolean +get_files_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) +{ + return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_files_emit); +} Added: soc2013/mattbw/backend/actions/get-files.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get-files.h Tue Jun 25 23:37:18 2013 (r253509) @@ -0,0 +1,29 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more files. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_GET_FILES_H_ +#define _PKGNG_BACKEND_GET_FILES_H_ + +#include /* gboolean */ +#include "../pk-backend.h" /* PkBackend */ + +gboolean get_files_thread(PkBackend *backend); + +#endif /* !_PKGNG_BACKEND_GET_FILES_H_ */ Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/db.c Tue Jun 25 23:37:18 2013 (r253509) @@ -19,11 +19,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include "pk-backend.h" #include "pkg.h" #include "db.h" /* prototypes */ +#include "iterate.h" /* pkg_func_ptr */ + +static const char *null_if_empty(const char *in); + +static gboolean +db_query_split(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + pkg_func_ptr emitter); /* * Opens a pkgdb ready for remote operations. This will always return TRUE if @@ -57,3 +71,131 @@ return success; } + +/* + * Performs a package database query against a PackageID, and then hands the + * matching results to an emitter function. + * + * The exact type of query depends on the repository given. + */ +gboolean +db_query_with_id(const gchar *package_id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + pkg_func_ptr emitter) +{ + gchar **parts; + gboolean success; + + success = FALSE; + + parts = pk_package_id_split(package_id); + if (parts == NULL) + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_ID_INVALID, + "invalid package id"); + else { + /* Parts of the package ID */ + const gchar *name; + const gchar *version; + const gchar *arch; + const gchar *data; + + /* + * Make really really REALLY sure that the PackageID fields + * either have sensible data in them, or are NULL. + */ + name = null_if_empty(parts[PK_PACKAGE_ID_NAME]); + version = null_if_empty(parts[PK_PACKAGE_ID_VERSION]); + arch = null_if_empty(parts[PK_PACKAGE_ID_ARCH]); + data = null_if_empty(parts[PK_PACKAGE_ID_DATA]); + + /* + * If the PackageID has a repository specified (even if it's + * "installed" i.e. currently installed package), running + * "get_details_query" directly should handle remote/local + * queries properly. + * + * If there is no repository specified, however (data is NULL), + * we may need to check both the local and (all) remote + * repositories, in that order. (TODO: local packages?) + */ + if (data == NULL) + /* Try local database first. */ + success = db_query_split(name, + version, + arch, + "installed", + backend, + db, + load_flags, + emitter); + if (success == FALSE) + success = db_query_split(name, version, arch, data, + backend, db, load_flags, emitter); + /* + * Assume any error is due to not finding packages. At time + * of writing this is true, but may change. + */ + if (success == FALSE) + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "package not found"); + g_strfreev(parts); + } + + return success; +} + +/* + * Looks the split PackageID up in the package databases. + * + * Usually, a remote query will be done on the repository named by "reponame". + * If reponame is NULL, a remote check will be done against all repostories. + * If it is "installed", a local check will be done. (This is in keeping + * with the special meaning of the "installed" repository in PackageIDs). + */ +static gboolean +db_query_split(const gchar *name, + const gchar *version, + const gchar *arch, + const gchar *reponame, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + pkg_func_ptr emitter) +{ + struct pkgdb_it *it; + gboolean success; + + success = FALSE; + + /* Are we doing a local query? */ + if (g_strcmp0(reponame, "installed") == 0) + it = pkgdb_query(db, name, MATCH_EXACT); + else + it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); + if (it) + success = iterate_id_matches(it, + backend, + name, + version, + arch, + reponame, + load_flags, + emitter); + return success; +} + +/* + * If the input pointer points to a string that is empty, return the null + * pointer; else pass through the pointer unmolested. + * + * This does NOT free anything! + */ +static const char * +null_if_empty(const char *in) +{ + return (in != NULL && strlen(in) == 0) ? NULL : in; +} Modified: soc2013/mattbw/backend/db.h ============================================================================== --- soc2013/mattbw/backend/db.h Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/db.h Tue Jun 25 23:37:18 2013 (r253509) @@ -26,6 +26,14 @@ #include "pk-backend.h" /* PkBackend */ #include "pkg.h" /* struct pkgdb */ +#include "iterate.h" /* pk_func_ptr */ + gboolean open_remote_db(struct pkgdb **db, PkBackend *backend); +gboolean +db_query_with_id(const gchar *package_id, + PkBackend *backend, + struct pkgdb *db, + int load_flags, + pkg_func_ptr emitter); #endif /* !_PKGNG_BACKEND_DETAILS_H_ */ Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/iterate.c Tue Jun 25 23:37:18 2013 (r253509) @@ -25,7 +25,7 @@ #include "iterate.h" /* Prototypes */ -#include "db.h" /* open_remote_db */ +#include "db.h" /* open_remote_db */ static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const @@ -53,7 +53,19 @@ pkg = NULL; match_id = NULL; do { - err = pkgdb_it_next(iterator, &pkg, fetch_flags); + /* + * Stop pkg from catching fire if we try to load files from + * non-installed packages. + */ + if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data, + "installed") != 0) { + pk_backend_error_code(backend, + PK_ERROR_ENUM_CANNOT_GET_FILELIST, + "Cannot get files for non-installed package." + ); + err = EPKG_FATAL; + } else + err = pkgdb_it_next(iterator, &pkg, fetch_flags); if (err == EPKG_OK && try_id_match(pkg, name, @@ -133,11 +145,12 @@ return result; } -/* Iterates over a set of PackageIDs provided for this job with a function. - * +/* + * Iterates over a set of PackageIDs provided for this job with a function. + * * This provides each iterating function call with an open database connection * and updates the percentage after each iteration. - * + * * It also *finishes* the backend job. */ gboolean Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jun 25 22:46:52 2013 (r253508) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Tue Jun 25 23:37:18 2013 (r253509) @@ -31,6 +31,7 @@ #include "pkg.h" #include "groups.h" /* available_groups */ +#include "actions/get-files.h" /* get_files_thread */ #include "actions/get-details.h"/* get_details_thread */ #define INTENTIONALLY_IGNORE(x) (void)(x) @@ -218,25 +219,13 @@ void pk_backend_get_files(PkBackend *backend, gchar **package_ids) { - guint i; - guint len; - const gchar *package_id; + INTENTIONALLY_IGNORE(package_ids); /* can be retrieved from + * backend */ pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); + pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); - len = g_strv_length(package_ids); - for (i = 0; i < len; i++) { - package_id = package_ids[i]; - if (g_strcmp0(package_id, "powertop;1.8-1.fc8;i386;fedora") == 0) - pk_backend_files(backend, package_id, "/usr/share/man/man1/boo;/usr/bin/xchat-gnome"); - else if (g_strcmp0(package_id, "kernel;2.6.23-0.115.rc3.git1.fc8;i386;installed") == 0) - pk_backend_files(backend, package_id, "/usr/share/man/man1;/usr/share/man/man1/gnome-power-manager.1.gz;/usr/lib/firefox-3.5.7/firefox"); - else if (g_strcmp0(package_id, "gtkhtml2;2.19.1-4.fc8;i386;fedora") == 0) - pk_backend_files(backend, package_id, "/usr/share/man/man1;/usr/bin/ck-xinit-session;/lib/libselinux.so.1"); - else - pk_backend_files(backend, package_id, "/usr/share/gnome-power-manager;/usr/bin/ck-xinit-session"); - } - pk_backend_finished(backend); + pk_backend_thread_create(backend, get_files_thread); } /** From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 04:35:42 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 461FC82B for ; Wed, 26 Jun 2013 04:35:42 +0000 (UTC) (envelope-from jmuniz@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 37D381CD8 for ; Wed, 26 Jun 2013 04:35:42 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5Q4Zg4o007437 for ; Wed, 26 Jun 2013 04:35:42 GMT (envelope-from jmuniz@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5Q4ZgbX007435 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 04:35:42 GMT (envelope-from jmuniz@FreeBSD.org) Date: Wed, 26 Jun 2013 04:35:42 GMT Message-Id: <201306260435.r5Q4ZgbX007435@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to jmuniz@FreeBSD.org using -f From: jmuniz@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253519 - soc2013/jmuniz/PackageKit-Setter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 04:35:42 -0000 Author: jmuniz Date: Wed Jun 26 04:35:41 2013 New Revision: 253519 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253519 Log: created initial pk-setter script Added: soc2013/jmuniz/PackageKit-Setter/pk-setter Added: soc2013/jmuniz/PackageKit-Setter/pk-setter ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/jmuniz/PackageKit-Setter/pk-setter Wed Jun 26 04:35:41 2013 (r253519) @@ -0,0 +1,135 @@ +#!/bin/sh +# +# Copyright (C) 2013 Justin Edward Muniz +# +# Licensed under the GNU General Public License Version 2 +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Script to list and select from possible PackageKit backends + +# There are three argugments that can be provided to this script: +# Instruction: mandatory; can be either 'list' or 'set' +# Backend Name: mandatory for 'set'; a string that identifies for the set instruction +# Prefix: optional; if included, must be a valid prefix path to the PackageKit installation + +# ENTRY POINT OF SCRIPT +# Make sure there is an appropriate number of arguements +if [ $# -eq 1 -o $# -eq 2 -o $# -eq 3 ]; then + # Determine if there is a user provided prefix and save it for later + setPrefix + # Determine if the user wants a list of backends, if so print it + listBackends + # Determine if the user wants a backend change, and process it + setBackend +fi +# Let the user know how to use this script +printUsage +# Return to the shell with failure +exit 1 +# EXIT POINT OF SCRIPT + +# This function presents the user with a list of available backednds +listBackends(){ + # Make sure that the user has requested a list of the available backends + if [ "$1" == "list" ]; then + # Create a string with each line representing the name of one backend + generateBackendList + # Print a header to describe the data to follow + echo "Available PackageKit backends:" + # Print the list of backends + echo "${PK_BACKENDS}" + # Return to the shell with success + exit 0 + fi +# End listBackends +} + +# This function uses the prefix and backend name to configure PackageKit to use the chosen backend +setBackend(){ + # Make sure that the user wants to select the backend + if [ "$1" == "set" ]; then + # Determine if the prefix contains the neccessary configuration file + if [ ! -e "${PK_PREFIX}etc/PackageKit/PackageKit.conf" ]; then + # Let the user know that the path does not lead to the configuration file + echo "Error: could not find PackageKit.conf, check prefix" + # Return to the shell with failure + exit 1 + fi + # Run the algorithm to create a new-line delimited list of available backends + generateBackendList + # Test the backend value provided against the list of valid backend names + if [ ${PK_BACKENDS} != *$2* ]; then + # Let the user know that they made a mistake + echo "The backend provided was not found, please check your entry" + # Give advice to the user since they made a mistake, then return to the shell with failure + printUsage + fi + # Find the first instance of "DefaultBackend" and replace the line to reflect the new backend + sed -i 's/DefaultBackend=.*/DefaultBackend='$2 + # Let the user know that the changes were successful + echo "PackageKit is now using the $2 backend" + # Return to the shell with success + exit 0 + fi +# End setBackend +} + +# This function determines which argument is the prefix, if any, and sets the value of PK_PREFIX for later +setPrefix(){ + # Set PK_PREFIX to default (root) prefix + ${PK_PREFIX}="/" + # Determine if there are three arguements + if [ $# -eq 3 ]; then + # Set PK_PREFIX for later + ${PK_PREFIX}="$3" + # If there were two arguements given + elif [ $# -eq 2 ]; then + # There must be a prefix if the "list" instruction is given + if [ "$1" == "list" ]; then + # Set PK_PREFIX to the third argument for later + ${PK_PREFIX}="$2" + fi + fi + # Find out if the path given does not end with a slash + if [ ${PK_PREFIX} != */ ]; then + # Then add a slash to the end to make a proper prefix + ${PK_PREFIX} .= "${PK_PREFIX}/" + fi + # Determine if the provided prefix even exists and if it refers to a directory + if [ ! -e "${PK_PREFIX}" -o ! -d "${PK_PREFIX}" ]; then + # Inform the user that the prefix provided does not refer to an existing directory + echo "Error: $2 is not a valid directory." + # Return to shell with failure + exit 1 + fi +# End setPrefix +} + +# This function explains to the user how to use this script, then exits +printUsage(){ + # Print the instructions to the user in a easily readable way + echo "pk-setter is used to select the PackageKit backend" + echo "usage: pk-setter list [prefix]" + echo " pk-setter set [backend] [prefix]" + echo "note: prefix is optional and defaults to the root directory" + echo " and refers to the intallation prefix of PackageKit" + # Returns to the shell with failure + exit 1 +# End printUsage +} + +# Create a list consisting of backend options, each on their own line +generateBackendList(){ + # Until a better way is figured out, a hardcoded set of options for backend selection are stored in PK_BACKENDS + ${PK_BACKENDS}="ports"$'\n'"pkgng"$'\n'"dummy (for debugging)" +# End generateBackendList +} + +# TODO for listBackends: might need exception handling for if list cannot be generated +# TODO: test validation and error handling in general +# TODO: check spelling +# TODO for generateBackendList: generate the list without hardcoding it +# TODO for setBackend: stop and start PackageKitd to load in the new backend \ No newline at end of file From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 09:58:24 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C3618B7 for ; Wed, 26 Jun 2013 09:58:24 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9C1251B01 for ; Wed, 26 Jun 2013 09:58:24 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5Q9wOwG021846 for ; Wed, 26 Jun 2013 09:58:24 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5Q9wOrR021845 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 09:58:24 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 09:58:24 GMT Message-Id: <201306260958.r5Q9wOrR021845@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253538 - soc2013/syuu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 09:58:24 -0000 Author: syuu Date: Wed Jun 26 09:58:23 2013 New Revision: 253538 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253538 Log: create repository for bhyve usb project Added: soc2013/syuu/ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 10:06:29 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 615F4358 for ; Wed, 26 Jun 2013 10:06:29 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 39D4A1BB7 for ; Wed, 26 Jun 2013 10:06:29 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QA6TnV041831 for ; Wed, 26 Jun 2013 10:06:29 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QA6TMu041827 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 10:06:29 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 10:06:29 GMT Message-Id: <201306261006.r5QA6TMu041827@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253542 - soc2013/syuu/bhyve_usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 10:06:29 -0000 Author: syuu Date: Wed Jun 26 10:06:29 2013 New Revision: 253542 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253542 Log: inital import for bhyve usb project Added: soc2013/syuu/bhyve_usb/ (props changed) - copied from r253541, mirror/FreeBSD/head/ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 16:31:13 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id BBA209D3 for ; Wed, 26 Jun 2013 16:31:13 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id AC14B1ED9 for ; Wed, 26 Jun 2013 16:31:13 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QGVDR0082149 for ; Wed, 26 Jun 2013 16:31:13 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QGVDFN082142 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 16:31:13 GMT (envelope-from mattbw@FreeBSD.org) Date: Wed, 26 Jun 2013 16:31:13 GMT Message-Id: <201306261631.r5QGVDFN082142@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253546 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 16:31:13 -0000 Author: mattbw Date: Wed Jun 26 16:31:13 2013 New Revision: 253546 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253546 Log: add get-repo-list; port to pkg1.1; some things need ironing out Added: soc2013/mattbw/backend/actions/get-repo-list.c soc2013/mattbw/backend/actions/get-repo-list.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/db.c soc2013/mattbw/backend/iterate.c soc2013/mattbw/backend/pk-backend-pkgng.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Wed Jun 26 12:57:21 2013 (r253545) +++ soc2013/mattbw/backend/Makefile Wed Jun 26 16:31:13 2013 (r253546) @@ -3,7 +3,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c -SRCS+= actions/get-details.c actions/get-files.c +SRCS+= actions/get-details.c actions/get-files.c actions/get-repo-list.c LIBDIR= /usr/local/lib/packagekit-backend Added: soc2013/mattbw/backend/actions/get-repo-list.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 16:31:13 2013 (r253546) @@ -0,0 +1,52 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "../pk-backend.h" +#include "pkg.h" + +/* + * The thread that performs a GetRepoList operation. Should be invoked by the + * pk_backend_get_repo_list hook. + */ +gboolean +get_repo_list_thread(PkBackend *backend) +{ + int err; + struct pkg_repo *repo; + + repo = NULL; + + for (;;) { + err = pkg_repos(&repo); + if (err == EPKG_OK && repo != NULL) + pk_backend_repo_detail(backend, +pkg_repo_ident(repo), +pkg_repo_name(repo), +pkg_repo_enabled(repo)); + else + break; + } + + return (err == EPKG_END ? TRUE : FALSE); +} + + Added: soc2013/mattbw/backend/actions/get-repo-list.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/actions/get-repo-list.h Wed Jun 26 16:31:13 2013 (r253546) @@ -0,0 +1,29 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more repo_list. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_GET_REPO_LIST_H_ +#define _PKGNG_BACKEND_GET_REPO_LIST_H_ + +#include /* gboolean */ +#include "../pk-backend.h" /* PkBackend */ + +gboolean get_repo_list_thread(PkBackend *backend); + +#endif /* !_PKGNG_BACKEND_GET_REPO_LIST_H_ */ Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Wed Jun 26 12:57:21 2013 (r253545) +++ soc2013/mattbw/backend/db.c Wed Jun 26 16:31:13 2013 (r253546) @@ -53,21 +53,30 @@ open_remote_db(struct pkgdb **db, PkBackend *backend) { gboolean success; + int access_return; int open_return; - /* TODO: pkgdb_access for pkg1.1 */ success = FALSE; - open_return = pkgdb_open(db, PKGDB_REMOTE); - if (open_return != EPKG_OK) - pk_backend_error_code(backend, - PK_ERROR_ENUM_INTERNAL_ERROR, - "pkgdb_open returned an error"); - else if (*db == NULL) + + access_return = pkgdb_access(PKGDB_MODE_READ | PKGDB_MODE_WRITE, + PKGDB_DB_LOCAL | PKGDB_DB_REPO); + if (access_return != EPKG_OK) pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, - "pkgdb_open gave us a null pointer"); - else - success = TRUE; + "cannot access database"); + else { + open_return = pkgdb_open(db, PKGDB_REMOTE); + if (open_return != EPKG_OK) + pk_backend_error_code(backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "pkgdb_open returned an error"); + else if (*db == NULL) + pk_backend_error_code(backend, + PK_ERROR_ENUM_INTERNAL_ERROR, + "pkgdb_open gave us a null pointer"); + else + success = TRUE; + } return success; } Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Wed Jun 26 12:57:21 2013 (r253545) +++ soc2013/mattbw/backend/iterate.c Wed Jun 26 16:31:13 2013 (r253546) @@ -91,13 +91,11 @@ const char *p_arch; const char *p_data; const char *p_name; - const char *p_reponame; const char *p_version; pkg_get(pkg, PKG_ARCH, &p_arch, PKG_NAME, &p_name, - PKG_REPONAME, &p_reponame, PKG_VERSION, &p_version); switch (pkg_type(pkg)) { @@ -107,8 +105,11 @@ case PKG_INSTALLED: p_data = "installed"; break; + case PKG_REMOTE: + pkg_get(pkg, PKG_REPONAME, &p_data); + break; default: - p_data = p_reponame; + p_data = "unknown"; break; } Modified: soc2013/mattbw/backend/pk-backend-pkgng.c ============================================================================== --- soc2013/mattbw/backend/pk-backend-pkgng.c Wed Jun 26 12:57:21 2013 (r253545) +++ soc2013/mattbw/backend/pk-backend-pkgng.c Wed Jun 26 16:31:13 2013 (r253546) @@ -33,6 +33,7 @@ #include "groups.h" /* available_groups */ #include "actions/get-files.h" /* get_files_thread */ #include "actions/get-details.h"/* get_details_thread */ +#include "actions/get-repo-list.h"/* get_repo_list_thread */ #define INTENTIONALLY_IGNORE(x) (void)(x) @@ -70,7 +71,10 @@ _progress_percentage = 0; - err = pkg_init(NULL); + err = EPKG_OK; + + if (!pkg_initialized()) + err = pkg_init(NULL); if (err) pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, @@ -1173,15 +1177,12 @@ void pk_backend_get_repo_list(PkBackend *backend, PkBitfield filters) { + INTENTIONALLY_IGNORE(filters); + pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY); - pk_backend_repo_detail(backend, "fedora", - "Fedora - 9", _repo_enabled_fedora); - if (!pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT)) { - pk_backend_repo_detail(backend, "development", - "Fedora - Development", _repo_enabled_devel); - } - pk_backend_repo_detail(backend, "livna-development", - "Livna for Fedora Core 8 - i386 - Development Tree", _repo_enabled_livna); + pk_backend_set_percentage(backend, PK_BACKEND_PERCENTAGE_INVALID); + + pk_backend_thread_create(backend, get_repo_list_thread); pk_backend_finished(backend); } @@ -1473,6 +1474,7 @@ */ } + /** * pk_backend_get_description: */ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 16:51:45 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 76EBDCDE for ; Wed, 26 Jun 2013 16:51:45 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 668921F9D for ; Wed, 26 Jun 2013 16:51:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QGpjMX060635 for ; Wed, 26 Jun 2013 16:51:45 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QGpjWx060625 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 16:51:45 GMT (envelope-from mattbw@FreeBSD.org) Date: Wed, 26 Jun 2013 16:51:45 GMT Message-Id: <201306261651.r5QGpjWx060625@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253547 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 16:51:45 -0000 Author: mattbw Date: Wed Jun 26 16:51:45 2013 New Revision: 253547 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253547 Log: generic pkg iterator traversal macro Added: soc2013/mattbw/backend/hash_traverse.h Modified: soc2013/mattbw/backend/actions/get-repo-list.c soc2013/mattbw/backend/iterate.c Modified: soc2013/mattbw/backend/actions/get-repo-list.c ============================================================================== --- soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 16:31:13 2013 (r253546) +++ soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 16:51:45 2013 (r253547) @@ -1,5 +1,4 @@ /*- - * * Copyright (C) 2013 Matt Windsor * * Licensed under the GNU General Public License Version 2 @@ -23,6 +22,8 @@ #include "../pk-backend.h" #include "pkg.h" +#include "../hash_traverse.h" /* HASH_FOR */ + /* * The thread that performs a GetRepoList operation. Should be invoked by the * pk_backend_get_repo_list hook. @@ -30,23 +31,16 @@ gboolean get_repo_list_thread(PkBackend *backend) { - int err; + int err; struct pkg_repo *repo; - + repo = NULL; - for (;;) { - err = pkg_repos(&repo); - if (err == EPKG_OK && repo != NULL) - pk_backend_repo_detail(backend, -pkg_repo_ident(repo), -pkg_repo_name(repo), -pkg_repo_enabled(repo)); - else - break; - } + for (HASH_FOR(err, pkg_repos, &repo)) + pk_backend_repo_detail(backend, + pkg_repo_ident(repo), + pkg_repo_name(repo), + pkg_repo_enabled(repo)); return (err == EPKG_END ? TRUE : FALSE); } - - Added: soc2013/mattbw/backend/hash_traverse.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/hash_traverse.h Wed Jun 26 16:51:45 2013 (r253547) @@ -0,0 +1,27 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_HASH_TRAVERSE_H_ +#define _PKGNG_BACKEND_HASH_TRAVERSE_H_ + +#define HASH_FOR(err, hash, ...) \ + (err) = hash(__VA_ARGS__); (err) == EPKG_OK; (err) = hash(__VA_ARGS__) + +#endif /* !_PKGNG_BACKEND_HASH_TRAVERSE_H_ */ Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Wed Jun 26 16:31:13 2013 (r253546) +++ soc2013/mattbw/backend/iterate.c Wed Jun 26 16:51:45 2013 (r253547) @@ -26,6 +26,7 @@ #include "iterate.h" /* Prototypes */ #include "db.h" /* open_remote_db */ +#include "hash_traverse.h" /* HASH_FOR */ static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const @@ -52,33 +53,33 @@ found = FALSE; pkg = NULL; match_id = NULL; - do { - /* - * Stop pkg from catching fire if we try to load files from - * non-installed packages. - */ - if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data, + + /* + * Stop pkg from catching fire if we try to load files from + * non-installed packages. + */ + if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data, "installed") != 0) { - pk_backend_error_code(backend, - PK_ERROR_ENUM_CANNOT_GET_FILELIST, + pk_backend_error_code(backend, + PK_ERROR_ENUM_CANNOT_GET_FILELIST, "Cannot get files for non-installed package." ); - err = EPKG_FATAL; - } else - err = pkgdb_it_next(iterator, &pkg, fetch_flags); - - if (err == EPKG_OK && try_id_match(pkg, - name, - version, - arch, - data, - &match_id) == TRUE) { - found = TRUE; - iterate_f(pkg, match_id, backend); + err = EPKG_FATAL; + } else { + for (HASH_FOR(err, pkgdb_it_next, iterator, &pkg, fetch_flags)) { + if (err == EPKG_OK && try_id_match(pkg, + name, + version, + arch, + data, + &match_id) == TRUE) { + found = TRUE; + iterate_f(pkg, match_id, backend); + } + if (match_id != NULL) + g_free(match_id); } - if (match_id != NULL) - g_free(match_id); - } while (err == EPKG_OK && found == FALSE); + } pkg_free(pkg); return found; From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 17:11:15 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 01C2319E for ; Wed, 26 Jun 2013 17:11:15 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id E72A41069 for ; Wed, 26 Jun 2013 17:11:14 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QHBEQ1049879 for ; Wed, 26 Jun 2013 17:11:14 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QHBENP049876 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 17:11:14 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 26 Jun 2013 17:11:14 GMT Message-Id: <201306261711.r5QHBENP049876@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253548 - in soc2013/dpl/head: contrib/bzip2 usr.bin/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 17:11:15 -0000 Author: dpl Date: Wed Jun 26 17:11:14 2013 New Revision: 253548 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253548 Log: Style nuances. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c soc2013/dpl/head/usr.bin/bzip2/Makefile Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Wed Jun 26 16:51:45 2013 (r253547) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Wed Jun 26 17:11:14 2013 (r253548) @@ -250,6 +250,7 @@ cmsg->cmsg_type = SCM_RIGHTS; memcpy(CMSG_DATA(cmsg), &fd, sizeof(int)); + printf("sendfd fd: %d\n", fd); if((sendmsg(s, &msg, 0)) != (int)iov.iov_len) return -1; return 0; @@ -279,6 +280,7 @@ return -1; cmsg = CMSG_FIRSTHDR(&msg); memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); + printf("recvfd fd: %d\n", fd); return fd; } #endif @@ -1396,21 +1398,20 @@ case ( 0 ): printf("Child\n"); if ((infd = recvfd(sv[1])) <= 0){ - fprintf ( stderr, "%s: Couldn't get fd infd: %s.\n", + fprintf ( stderr, "%s: Couldn't get infd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); } - printf("inStr fd received: %d\n",infd); - inStr = fdopen(infd, "rb"); if ((outfd = recvfd(sv[1])) <= 0){ - fprintf ( stderr, "%s: Couldn't get fd outfd: %s.\n", + fprintf ( stderr, "%s: Couldn't get outfd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); } - printf("outStr fd received: %d\n",outfd); + printf("Child: infd:%d, outfd:%d\n", infd, outfd); + inStr = fdopen(infd, "rb"); outStr = fdopen(outfd, "wb"); if (cap_enter() < 0) { @@ -1438,26 +1439,25 @@ } deleteOutputOnInterrupt = False; - exit(0); - # if CAPSICUM + exit(0); break; default: - printf("infd:%d, outfd:%d\n", infd, outfd); + printf("Parent: infd:%d, outfd:%d\n", infd, outfd); if (sendfd(sv[0], infd) < 0){ - fprintf ( stderr, "%s: Couldn't send fd infd: %s.\n", + fprintf ( stderr, "%s: Couldn't send infd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); } if (sendfd(sv[0], outfd) < 0){ - fprintf ( stderr, "%s: Couldn't send fd outfd: %s.\n", + fprintf ( stderr, "%s: Couldn't send outfd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); } - wait(0); + wait(NULL); return; } # endif Modified: soc2013/dpl/head/usr.bin/bzip2/Makefile ============================================================================== --- soc2013/dpl/head/usr.bin/bzip2/Makefile Wed Jun 26 16:51:45 2013 (r253547) +++ soc2013/dpl/head/usr.bin/bzip2/Makefile Wed Jun 26 17:11:14 2013 (r253548) @@ -27,11 +27,11 @@ .for f in ${REFFILES} ${f}: ${f}.gz.uu - uudecode -p ${BZ2DIR}/${f}.gz.uu | gunzip > ${f} + @uudecode -p ${BZ2DIR}/${f}.gz.uu | gunzip > ${f} .endfor .for f in ${DREFFILES} ${f}: ${f}.uu - uudecode ${BZ2DIR}/${f}.uu + @uudecode ${BZ2DIR}/${f}.uu .endfor test: bzip2 ${TESTFILES} From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 19:23:54 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E878CDB4 for ; Wed, 26 Jun 2013 19:23:54 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id D8A8517EC for ; Wed, 26 Jun 2013 19:23:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QJNsNI009760 for ; Wed, 26 Jun 2013 19:23:54 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QJNsTl009755 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 19:23:54 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 19:23:54 GMT Message-Id: <201306261923.r5QJNsTl009755@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253552 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 19:23:55 -0000 Author: syuu Date: Wed Jun 26 19:23:54 2013 New Revision: 253552 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253552 Log: inital import of UHCI emulator Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Jun 26 18:12:38 2013 (r253551) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Jun 26 19:23:54 2013 (r253552) @@ -15,6 +15,9 @@ .PATH: ${.CURDIR}/../../sys/amd64/vmm SRCS+= vmm_instruction_emul.c +.PATH: ${.CURDIR}/usb +SRCS+= core.c hcd-uhci.c + NO_MAN= DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBPTHREAD} Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c Wed Jun 26 19:23:54 2013 (r253552) @@ -0,0 +1,788 @@ +/* + * QEMU USB emulation + * + * Copyright (c) 2005 Fabrice Bellard + * + * 2008 Generic packet handler rewrite by Max Krasnyansky + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "qemu-common.h" +#include "hw/usb.h" +#include "qemu/iov.h" +#include "trace.h" + +void usb_attach(USBPort *port) +{ + USBDevice *dev = port->dev; + + assert(dev != NULL); + assert(dev->attached); + assert(dev->state == USB_STATE_NOTATTACHED); + port->ops->attach(port); + dev->state = USB_STATE_ATTACHED; + usb_device_handle_attach(dev); +} + +void usb_detach(USBPort *port) +{ + USBDevice *dev = port->dev; + + assert(dev != NULL); + assert(dev->state != USB_STATE_NOTATTACHED); + port->ops->detach(port); + dev->state = USB_STATE_NOTATTACHED; +} + +void usb_port_reset(USBPort *port) +{ + USBDevice *dev = port->dev; + + assert(dev != NULL); + usb_detach(port); + usb_attach(port); + usb_device_reset(dev); +} + +void usb_device_reset(USBDevice *dev) +{ + if (dev == NULL || !dev->attached) { + return; + } + dev->remote_wakeup = 0; + dev->addr = 0; + dev->state = USB_STATE_DEFAULT; + usb_device_handle_reset(dev); +} + +void usb_wakeup(USBEndpoint *ep, unsigned int stream) +{ + USBDevice *dev = ep->dev; + USBBus *bus = usb_bus_from_device(dev); + + if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) { + dev->port->ops->wakeup(dev->port); + } + if (bus->ops->wakeup_endpoint) { + bus->ops->wakeup_endpoint(bus, ep, stream); + } +} + +/**********************/ + +/* generic USB device helpers (you are not forced to use them when + writing your USB device driver, but they help handling the + protocol) +*/ + +#define SETUP_STATE_IDLE 0 +#define SETUP_STATE_SETUP 1 +#define SETUP_STATE_DATA 2 +#define SETUP_STATE_ACK 3 +#define SETUP_STATE_PARAM 4 + +static void do_token_setup(USBDevice *s, USBPacket *p) +{ + int request, value, index; + + if (p->iov.size != 8) { + p->status = USB_RET_STALL; + return; + } + + usb_packet_copy(p, s->setup_buf, p->iov.size); + p->actual_length = 0; + s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6]; + s->setup_index = 0; + + request = (s->setup_buf[0] << 8) | s->setup_buf[1]; + value = (s->setup_buf[3] << 8) | s->setup_buf[2]; + index = (s->setup_buf[5] << 8) | s->setup_buf[4]; + + if (s->setup_buf[0] & USB_DIR_IN) { + usb_device_handle_control(s, p, request, value, index, + s->setup_len, s->data_buf); + if (p->status == USB_RET_ASYNC) { + s->setup_state = SETUP_STATE_SETUP; + } + if (p->status != USB_RET_SUCCESS) { + return; + } + + if (p->actual_length < s->setup_len) { + s->setup_len = p->actual_length; + } + s->setup_state = SETUP_STATE_DATA; + } else { + if (s->setup_len > sizeof(s->data_buf)) { + fprintf(stderr, + "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n", + s->setup_len, sizeof(s->data_buf)); + p->status = USB_RET_STALL; + return; + } + if (s->setup_len == 0) + s->setup_state = SETUP_STATE_ACK; + else + s->setup_state = SETUP_STATE_DATA; + } + + p->actual_length = 8; +} + +static void do_token_in(USBDevice *s, USBPacket *p) +{ + int request, value, index; + + assert(p->ep->nr == 0); + + request = (s->setup_buf[0] << 8) | s->setup_buf[1]; + value = (s->setup_buf[3] << 8) | s->setup_buf[2]; + index = (s->setup_buf[5] << 8) | s->setup_buf[4]; + + switch(s->setup_state) { + case SETUP_STATE_ACK: + if (!(s->setup_buf[0] & USB_DIR_IN)) { + usb_device_handle_control(s, p, request, value, index, + s->setup_len, s->data_buf); + if (p->status == USB_RET_ASYNC) { + return; + } + s->setup_state = SETUP_STATE_IDLE; + p->actual_length = 0; + } + break; + + case SETUP_STATE_DATA: + if (s->setup_buf[0] & USB_DIR_IN) { + int len = s->setup_len - s->setup_index; + if (len > p->iov.size) { + len = p->iov.size; + } + usb_packet_copy(p, s->data_buf + s->setup_index, len); + s->setup_index += len; + if (s->setup_index >= s->setup_len) { + s->setup_state = SETUP_STATE_ACK; + } + return; + } + s->setup_state = SETUP_STATE_IDLE; + p->status = USB_RET_STALL; + break; + + default: + p->status = USB_RET_STALL; + } +} + +static void do_token_out(USBDevice *s, USBPacket *p) +{ + assert(p->ep->nr == 0); + + switch(s->setup_state) { + case SETUP_STATE_ACK: + if (s->setup_buf[0] & USB_DIR_IN) { + s->setup_state = SETUP_STATE_IDLE; + /* transfer OK */ + } else { + /* ignore additional output */ + } + break; + + case SETUP_STATE_DATA: + if (!(s->setup_buf[0] & USB_DIR_IN)) { + int len = s->setup_len - s->setup_index; + if (len > p->iov.size) { + len = p->iov.size; + } + usb_packet_copy(p, s->data_buf + s->setup_index, len); + s->setup_index += len; + if (s->setup_index >= s->setup_len) { + s->setup_state = SETUP_STATE_ACK; + } + return; + } + s->setup_state = SETUP_STATE_IDLE; + p->status = USB_RET_STALL; + break; + + default: + p->status = USB_RET_STALL; + } +} + +static void do_parameter(USBDevice *s, USBPacket *p) +{ + int i, request, value, index; + + for (i = 0; i < 8; i++) { + s->setup_buf[i] = p->parameter >> (i*8); + } + + s->setup_state = SETUP_STATE_PARAM; + s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6]; + s->setup_index = 0; + + request = (s->setup_buf[0] << 8) | s->setup_buf[1]; + value = (s->setup_buf[3] << 8) | s->setup_buf[2]; + index = (s->setup_buf[5] << 8) | s->setup_buf[4]; + + if (s->setup_len > sizeof(s->data_buf)) { + fprintf(stderr, + "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n", + s->setup_len, sizeof(s->data_buf)); + p->status = USB_RET_STALL; + return; + } + + if (p->pid == USB_TOKEN_OUT) { + usb_packet_copy(p, s->data_buf, s->setup_len); + } + + usb_device_handle_control(s, p, request, value, index, + s->setup_len, s->data_buf); + if (p->status == USB_RET_ASYNC) { + return; + } + + if (p->actual_length < s->setup_len) { + s->setup_len = p->actual_length; + } + if (p->pid == USB_TOKEN_IN) { + p->actual_length = 0; + usb_packet_copy(p, s->data_buf, s->setup_len); + } +} + +/* ctrl complete function for devices which use usb_generic_handle_packet and + may return USB_RET_ASYNC from their handle_control callback. Device code + which does this *must* call this function instead of the normal + usb_packet_complete to complete their async control packets. */ +void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p) +{ + if (p->status < 0) { + s->setup_state = SETUP_STATE_IDLE; + } + + switch (s->setup_state) { + case SETUP_STATE_SETUP: + if (p->actual_length < s->setup_len) { + s->setup_len = p->actual_length; + } + s->setup_state = SETUP_STATE_DATA; + p->actual_length = 8; + break; + + case SETUP_STATE_ACK: + s->setup_state = SETUP_STATE_IDLE; + p->actual_length = 0; + break; + + case SETUP_STATE_PARAM: + if (p->actual_length < s->setup_len) { + s->setup_len = p->actual_length; + } + if (p->pid == USB_TOKEN_IN) { + p->actual_length = 0; + usb_packet_copy(p, s->data_buf, s->setup_len); + } + break; + + default: + break; + } + usb_packet_complete(s, p); +} + +/* XXX: fix overflow */ +int set_usb_string(uint8_t *buf, const char *str) +{ + int len, i; + uint8_t *q; + + q = buf; + len = strlen(str); + *q++ = 2 * len + 2; + *q++ = 3; + for(i = 0; i < len; i++) { + *q++ = str[i]; + *q++ = 0; + } + return q - buf; +} + +USBDevice *usb_find_device(USBPort *port, uint8_t addr) +{ + USBDevice *dev = port->dev; + + if (dev == NULL || !dev->attached || dev->state != USB_STATE_DEFAULT) { + return NULL; + } + if (dev->addr == addr) { + return dev; + } + return usb_device_find_device(dev, addr); +} + +static void usb_process_one(USBPacket *p) +{ + USBDevice *dev = p->ep->dev; + + /* + * Handlers expect status to be initialized to USB_RET_SUCCESS, but it + * can be USB_RET_NAK here from a previous usb_process_one() call, + * or USB_RET_ASYNC from going through usb_queue_one(). + */ + p->status = USB_RET_SUCCESS; + + if (p->ep->nr == 0) { + /* control pipe */ + if (p->parameter) { + do_parameter(dev, p); + return; + } + switch (p->pid) { + case USB_TOKEN_SETUP: + do_token_setup(dev, p); + break; + case USB_TOKEN_IN: + do_token_in(dev, p); + break; + case USB_TOKEN_OUT: + do_token_out(dev, p); + break; + default: + p->status = USB_RET_STALL; + } + } else { + /* data pipe */ + usb_device_handle_data(dev, p); + } +} + +static void usb_queue_one(USBPacket *p) +{ + usb_packet_set_state(p, USB_PACKET_QUEUED); + QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue); + p->status = USB_RET_ASYNC; +} + +/* Hand over a packet to a device for processing. p->status == + USB_RET_ASYNC indicates the processing isn't finished yet, the + driver will call usb_packet_complete() when done processing it. */ +void usb_handle_packet(USBDevice *dev, USBPacket *p) +{ + if (dev == NULL) { + p->status = USB_RET_NODEV; + return; + } + assert(dev == p->ep->dev); + assert(dev->state == USB_STATE_DEFAULT); + usb_packet_check_state(p, USB_PACKET_SETUP); + assert(p->ep != NULL); + + /* Submitting a new packet clears halt */ + if (p->ep->halted) { + assert(QTAILQ_EMPTY(&p->ep->queue)); + p->ep->halted = false; + } + + if (QTAILQ_EMPTY(&p->ep->queue) || p->ep->pipeline) { + usb_process_one(p); + if (p->status == USB_RET_ASYNC) { + /* hcd drivers cannot handle async for isoc */ + assert(p->ep->type != USB_ENDPOINT_XFER_ISOC); + /* using async for interrupt packets breaks migration */ + assert(p->ep->type != USB_ENDPOINT_XFER_INT || + (dev->flags & (1 << USB_DEV_FLAG_IS_HOST))); + usb_packet_set_state(p, USB_PACKET_ASYNC); + QTAILQ_INSERT_TAIL(&p->ep->queue, p, queue); + } else if (p->status == USB_RET_ADD_TO_QUEUE) { + usb_queue_one(p); + } else { + /* + * When pipelining is enabled usb-devices must always return async, + * otherwise packets can complete out of order! + */ + assert(!p->ep->pipeline || QTAILQ_EMPTY(&p->ep->queue)); + if (p->status != USB_RET_NAK) { + usb_packet_set_state(p, USB_PACKET_COMPLETE); + } + } + } else { + usb_queue_one(p); + } +} + +void usb_packet_complete_one(USBDevice *dev, USBPacket *p) +{ + USBEndpoint *ep = p->ep; + + assert(QTAILQ_FIRST(&ep->queue) == p); + assert(p->status != USB_RET_ASYNC && p->status != USB_RET_NAK); + + if (p->status != USB_RET_SUCCESS || + (p->short_not_ok && (p->actual_length < p->iov.size))) { + ep->halted = true; + } + usb_packet_set_state(p, USB_PACKET_COMPLETE); + QTAILQ_REMOVE(&ep->queue, p, queue); + dev->port->ops->complete(dev->port, p); +} + +/* Notify the controller that an async packet is complete. This should only + be called for packets previously deferred by returning USB_RET_ASYNC from + handle_packet. */ +void usb_packet_complete(USBDevice *dev, USBPacket *p) +{ + USBEndpoint *ep = p->ep; + + usb_packet_check_state(p, USB_PACKET_ASYNC); + usb_packet_complete_one(dev, p); + + while (!QTAILQ_EMPTY(&ep->queue)) { + p = QTAILQ_FIRST(&ep->queue); + if (ep->halted) { + /* Empty the queue on a halt */ + p->status = USB_RET_REMOVE_FROM_QUEUE; + dev->port->ops->complete(dev->port, p); + continue; + } + if (p->state == USB_PACKET_ASYNC) { + break; + } + usb_packet_check_state(p, USB_PACKET_QUEUED); + usb_process_one(p); + if (p->status == USB_RET_ASYNC) { + usb_packet_set_state(p, USB_PACKET_ASYNC); + break; + } + usb_packet_complete_one(ep->dev, p); + } +} + +/* Cancel an active packet. The packed must have been deferred by + returning USB_RET_ASYNC from handle_packet, and not yet + completed. */ +void usb_cancel_packet(USBPacket * p) +{ + bool callback = (p->state == USB_PACKET_ASYNC); + assert(usb_packet_is_inflight(p)); + usb_packet_set_state(p, USB_PACKET_CANCELED); + QTAILQ_REMOVE(&p->ep->queue, p, queue); + if (callback) { + usb_device_cancel_packet(p->ep->dev, p); + } +} + + +void usb_packet_init(USBPacket *p) +{ + qemu_iovec_init(&p->iov, 1); +} + +static const char *usb_packet_state_name(USBPacketState state) +{ + static const char *name[] = { + [USB_PACKET_UNDEFINED] = "undef", + [USB_PACKET_SETUP] = "setup", + [USB_PACKET_QUEUED] = "queued", + [USB_PACKET_ASYNC] = "async", + [USB_PACKET_COMPLETE] = "complete", + [USB_PACKET_CANCELED] = "canceled", + }; + if (state < ARRAY_SIZE(name)) { + return name[state]; + } + return "INVALID"; +} + +void usb_packet_check_state(USBPacket *p, USBPacketState expected) +{ + USBDevice *dev; + USBBus *bus; + + if (p->state == expected) { + return; + } + dev = p->ep->dev; + bus = usb_bus_from_device(dev); + trace_usb_packet_state_fault(bus->busnr, dev->port->path, p->ep->nr, p, + usb_packet_state_name(p->state), + usb_packet_state_name(expected)); + assert(!"usb packet state check failed"); +} + +void usb_packet_set_state(USBPacket *p, USBPacketState state) +{ + if (p->ep) { + USBDevice *dev = p->ep->dev; + USBBus *bus = usb_bus_from_device(dev); + trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p, + usb_packet_state_name(p->state), + usb_packet_state_name(state)); + } else { + trace_usb_packet_state_change(-1, "", -1, p, + usb_packet_state_name(p->state), + usb_packet_state_name(state)); + } + p->state = state; +} + +void usb_packet_setup(USBPacket *p, int pid, + USBEndpoint *ep, unsigned int stream, + uint64_t id, bool short_not_ok, bool int_req) +{ + assert(!usb_packet_is_inflight(p)); + assert(p->iov.iov != NULL); + p->id = id; + p->pid = pid; + p->ep = ep; + p->stream = stream; + p->status = USB_RET_SUCCESS; + p->actual_length = 0; + p->parameter = 0; + p->short_not_ok = short_not_ok; + p->int_req = int_req; + p->combined = NULL; + qemu_iovec_reset(&p->iov); + usb_packet_set_state(p, USB_PACKET_SETUP); +} + +void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len) +{ + qemu_iovec_add(&p->iov, ptr, len); +} + +void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes) +{ + QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; + + assert(p->actual_length >= 0); + assert(p->actual_length + bytes <= iov->size); + switch (p->pid) { + case USB_TOKEN_SETUP: + case USB_TOKEN_OUT: + iov_to_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes); + break; + case USB_TOKEN_IN: + iov_from_buf(iov->iov, iov->niov, p->actual_length, ptr, bytes); + break; + default: + fprintf(stderr, "%s: invalid pid: %x\n", __func__, p->pid); + abort(); + } + p->actual_length += bytes; +} + +void usb_packet_skip(USBPacket *p, size_t bytes) +{ + QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; + + assert(p->actual_length >= 0); + assert(p->actual_length + bytes <= iov->size); + if (p->pid == USB_TOKEN_IN) { + iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes); + } + p->actual_length += bytes; +} + +size_t usb_packet_size(USBPacket *p) +{ + return p->combined ? p->combined->iov.size : p->iov.size; +} + +void usb_packet_cleanup(USBPacket *p) +{ + assert(!usb_packet_is_inflight(p)); + qemu_iovec_destroy(&p->iov); +} + +void usb_ep_reset(USBDevice *dev) +{ + int ep; + + dev->ep_ctl.nr = 0; + dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL; + dev->ep_ctl.ifnum = 0; + dev->ep_ctl.dev = dev; + dev->ep_ctl.pipeline = false; + for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) { + dev->ep_in[ep].nr = ep + 1; + dev->ep_out[ep].nr = ep + 1; + dev->ep_in[ep].pid = USB_TOKEN_IN; + dev->ep_out[ep].pid = USB_TOKEN_OUT; + dev->ep_in[ep].type = USB_ENDPOINT_XFER_INVALID; + dev->ep_out[ep].type = USB_ENDPOINT_XFER_INVALID; + dev->ep_in[ep].ifnum = USB_INTERFACE_INVALID; + dev->ep_out[ep].ifnum = USB_INTERFACE_INVALID; + dev->ep_in[ep].dev = dev; + dev->ep_out[ep].dev = dev; + dev->ep_in[ep].pipeline = false; + dev->ep_out[ep].pipeline = false; + } +} + +void usb_ep_init(USBDevice *dev) +{ + int ep; + + usb_ep_reset(dev); + QTAILQ_INIT(&dev->ep_ctl.queue); + for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) { + QTAILQ_INIT(&dev->ep_in[ep].queue); + QTAILQ_INIT(&dev->ep_out[ep].queue); + } +} + +void usb_ep_dump(USBDevice *dev) +{ + static const char *tname[] = { + [USB_ENDPOINT_XFER_CONTROL] = "control", + [USB_ENDPOINT_XFER_ISOC] = "isoc", + [USB_ENDPOINT_XFER_BULK] = "bulk", + [USB_ENDPOINT_XFER_INT] = "int", + }; + int ifnum, ep, first; + + fprintf(stderr, "Device \"%s\", config %d\n", + dev->product_desc, dev->configuration); + for (ifnum = 0; ifnum < 16; ifnum++) { + first = 1; + for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) { + if (dev->ep_in[ep].type != USB_ENDPOINT_XFER_INVALID && + dev->ep_in[ep].ifnum == ifnum) { + if (first) { + first = 0; + fprintf(stderr, " Interface %d, alternative %d\n", + ifnum, dev->altsetting[ifnum]); + } + fprintf(stderr, " Endpoint %d, IN, %s, %d max\n", ep, + tname[dev->ep_in[ep].type], + dev->ep_in[ep].max_packet_size); + } + if (dev->ep_out[ep].type != USB_ENDPOINT_XFER_INVALID && + dev->ep_out[ep].ifnum == ifnum) { + if (first) { + first = 0; + fprintf(stderr, " Interface %d, alternative %d\n", + ifnum, dev->altsetting[ifnum]); + } + fprintf(stderr, " Endpoint %d, OUT, %s, %d max\n", ep, + tname[dev->ep_out[ep].type], + dev->ep_out[ep].max_packet_size); + } + } + } + fprintf(stderr, "--\n"); +} + +struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *eps; + + if (dev == NULL) { + return NULL; + } + eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; + if (ep == 0) { + return &dev->ep_ctl; + } + assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT); + assert(ep > 0 && ep <= USB_MAX_ENDPOINTS); + return eps + ep - 1; +} + +uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + return uep->type; +} + +void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + uep->type = type; +} + +uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + return uep->ifnum; +} + +void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + uep->ifnum = ifnum; +} + +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + int size, microframes; + + size = raw & 0x7ff; + switch ((raw >> 11) & 3) { + case 1: + microframes = 2; + break; + case 2: + microframes = 3; + break; + default: + microframes = 1; + break; + } + uep->max_packet_size = size * microframes; +} + +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + return uep->max_packet_size; +} + +void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + uep->pipeline = enabled; +} + +void usb_ep_set_halted(USBDevice *dev, int pid, int ep, bool halted) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + uep->halted = halted; +} + +USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, + uint64_t id) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + USBPacket *p; + + QTAILQ_FOREACH(p, &uep->queue, queue) { + if (p->id == id) { + return p; + } + } + + return NULL; +} Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Jun 26 19:23:54 2013 (r253552) @@ -0,0 +1,1404 @@ +/* + * USB UHCI controller emulation + * + * Copyright (c) 2005 Fabrice Bellard + * + * Copyright (c) 2008 Max Krasnyansky + * Magor rewrite of the UHCI data structures parser and frame processor + * Support for fully async operation and multiple outstanding transactions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "hw/hw.h" +#include "hw/usb.h" +#include "hw/pci/pci.h" +#include "qemu/timer.h" +#include "qemu/iov.h" +#include "sysemu/dma.h" +#include "trace.h" + +//#define DEBUG +//#define DEBUG_DUMP_DATA + +#define UHCI_CMD_FGR (1 << 4) +#define UHCI_CMD_EGSM (1 << 3) +#define UHCI_CMD_GRESET (1 << 2) +#define UHCI_CMD_HCRESET (1 << 1) +#define UHCI_CMD_RS (1 << 0) + +#define UHCI_STS_HCHALTED (1 << 5) +#define UHCI_STS_HCPERR (1 << 4) +#define UHCI_STS_HSERR (1 << 3) +#define UHCI_STS_RD (1 << 2) +#define UHCI_STS_USBERR (1 << 1) +#define UHCI_STS_USBINT (1 << 0) + +#define TD_CTRL_SPD (1 << 29) +#define TD_CTRL_ERROR_SHIFT 27 +#define TD_CTRL_IOS (1 << 25) +#define TD_CTRL_IOC (1 << 24) +#define TD_CTRL_ACTIVE (1 << 23) +#define TD_CTRL_STALL (1 << 22) +#define TD_CTRL_BABBLE (1 << 20) +#define TD_CTRL_NAK (1 << 19) +#define TD_CTRL_TIMEOUT (1 << 18) + +#define UHCI_PORT_SUSPEND (1 << 12) +#define UHCI_PORT_RESET (1 << 9) +#define UHCI_PORT_LSDA (1 << 8) +#define UHCI_PORT_RD (1 << 6) +#define UHCI_PORT_ENC (1 << 3) +#define UHCI_PORT_EN (1 << 2) +#define UHCI_PORT_CSC (1 << 1) +#define UHCI_PORT_CCS (1 << 0) + +#define UHCI_PORT_READ_ONLY (0x1bb) +#define UHCI_PORT_WRITE_CLEAR (UHCI_PORT_CSC | UHCI_PORT_ENC) + +#define FRAME_TIMER_FREQ 1000 + +#define FRAME_MAX_LOOPS 256 + +/* Must be large enough to handle 10 frame delay for initial isoc requests */ +#define QH_VALID 32 + +#define MAX_FRAMES_PER_TICK (QH_VALID / 2) + +#define NB_PORTS 2 + +enum { + TD_RESULT_STOP_FRAME = 10, + TD_RESULT_COMPLETE, + TD_RESULT_NEXT_QH, + TD_RESULT_ASYNC_START, + TD_RESULT_ASYNC_CONT, +}; + +typedef struct UHCIState UHCIState; +typedef struct UHCIAsync UHCIAsync; +typedef struct UHCIQueue UHCIQueue; +typedef struct UHCIInfo UHCIInfo; +typedef struct UHCIPCIDeviceClass UHCIPCIDeviceClass; + +struct UHCIInfo { + const char *name; + uint16_t vendor_id; + uint16_t device_id; + uint8_t revision; + uint8_t irq_pin; + int (*initfn)(PCIDevice *dev); + bool unplug; +}; + +struct UHCIPCIDeviceClass { + PCIDeviceClass parent_class; + UHCIInfo info; +}; + +/* + * Pending async transaction. + * 'packet' must be the first field because completion + * handler does "(UHCIAsync *) pkt" cast. + */ + +struct UHCIAsync { + USBPacket packet; + uint8_t static_buf[64]; /* 64 bytes is enough, except for isoc packets */ + uint8_t *buf; + UHCIQueue *queue; + QTAILQ_ENTRY(UHCIAsync) next; + uint32_t td_addr; + uint8_t done; +}; + +struct UHCIQueue { + uint32_t qh_addr; + uint32_t token; + UHCIState *uhci; + USBEndpoint *ep; + QTAILQ_ENTRY(UHCIQueue) next; + QTAILQ_HEAD(asyncs_head, UHCIAsync) asyncs; + int8_t valid; +}; + +typedef struct UHCIPort { + USBPort port; + uint16_t ctrl; +} UHCIPort; + +struct UHCIState { + PCIDevice dev; + MemoryRegion io_bar; + USBBus bus; /* Note unused when we're a companion controller */ + uint16_t cmd; /* cmd register */ + uint16_t status; + uint16_t intr; /* interrupt enable register */ + uint16_t frnum; /* frame number */ + uint32_t fl_base_addr; /* frame list base address */ + uint8_t sof_timing; + uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */ + int64_t expire_time; + QEMUTimer *frame_timer; + QEMUBH *bh; + uint32_t frame_bytes; + uint32_t frame_bandwidth; + bool completions_only; + UHCIPort ports[NB_PORTS]; + + /* Interrupts that should be raised at the end of the current frame. */ + uint32_t pending_int_mask; + int irq_pin; + + /* Active packets */ + QTAILQ_HEAD(, UHCIQueue) queues; + uint8_t num_ports_vmstate; + + /* Properties */ + char *masterbus; + uint32_t firstport; + uint32_t maxframes; +}; + +typedef struct UHCI_TD { + uint32_t link; + uint32_t ctrl; /* see TD_CTRL_xxx */ + uint32_t token; + uint32_t buffer; +} UHCI_TD; + +typedef struct UHCI_QH { + uint32_t link; + uint32_t el_link; +} UHCI_QH; + +static void uhci_async_cancel(UHCIAsync *async); +static void uhci_queue_fill(UHCIQueue *q, UHCI_TD *td); + +static inline int32_t uhci_queue_token(UHCI_TD *td) +{ *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 19:40:54 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B32EC2DC for ; Wed, 26 Jun 2013 19:40:54 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9585F1896 for ; Wed, 26 Jun 2013 19:40:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QJesff036929 for ; Wed, 26 Jun 2013 19:40:54 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QJeshN036907 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 19:40:54 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 19:40:54 GMT Message-Id: <201306261940.r5QJeshN036907@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253553 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve: . usb usb/include usb/include/hw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 19:40:54 -0000 Author: syuu Date: Wed Jun 26 19:40:54 2013 New Revision: 253553 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253553 Log: move headers into usb/include dir Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h - copied unchanged from r253552, soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/usb.h Deleted: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/usb.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Jun 26 19:23:54 2013 (r253552) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/Makefile Wed Jun 26 19:40:54 2013 (r253553) @@ -16,6 +16,7 @@ SRCS+= vmm_instruction_emul.c .PATH: ${.CURDIR}/usb +CFLAGS+=-I${.CURDIR}/usb/include SRCS+= core.c hcd-uhci.c NO_MAN= Copied: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h (from r253552, soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/usb.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Wed Jun 26 19:40:54 2013 (r253553, copy of r253552, soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/usb.h) @@ -0,0 +1,572 @@ +#ifndef QEMU_USB_H +#define QEMU_USB_H + +/* + * QEMU USB API + * + * Copyright (c) 2005 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "hw/qdev.h" +#include "qemu/queue.h" + +/* Constants related to the USB / PCI interaction */ +#define USB_SBRN 0x60 /* Serial Bus Release Number Register */ +#define USB_RELEASE_1 0x10 /* USB 1.0 */ +#define USB_RELEASE_2 0x20 /* USB 2.0 */ +#define USB_RELEASE_3 0x30 /* USB 3.0 */ + +#define USB_TOKEN_SETUP 0x2d +#define USB_TOKEN_IN 0x69 /* device -> host */ +#define USB_TOKEN_OUT 0xe1 /* host -> device */ + +#define USB_RET_SUCCESS (0) +#define USB_RET_NODEV (-1) +#define USB_RET_NAK (-2) +#define USB_RET_STALL (-3) +#define USB_RET_BABBLE (-4) +#define USB_RET_IOERROR (-5) +#define USB_RET_ASYNC (-6) +#define USB_RET_ADD_TO_QUEUE (-7) +#define USB_RET_REMOVE_FROM_QUEUE (-8) + +#define USB_SPEED_LOW 0 +#define USB_SPEED_FULL 1 +#define USB_SPEED_HIGH 2 +#define USB_SPEED_SUPER 3 + +#define USB_SPEED_MASK_LOW (1 << USB_SPEED_LOW) +#define USB_SPEED_MASK_FULL (1 << USB_SPEED_FULL) +#define USB_SPEED_MASK_HIGH (1 << USB_SPEED_HIGH) +#define USB_SPEED_MASK_SUPER (1 << USB_SPEED_SUPER) + +#define USB_STATE_NOTATTACHED 0 +#define USB_STATE_ATTACHED 1 +//#define USB_STATE_POWERED 2 +#define USB_STATE_DEFAULT 3 +//#define USB_STATE_ADDRESS 4 +//#define USB_STATE_CONFIGURED 5 +#define USB_STATE_SUSPENDED 6 + +#define USB_CLASS_AUDIO 1 +#define USB_CLASS_COMM 2 +#define USB_CLASS_HID 3 +#define USB_CLASS_PHYSICAL 5 +#define USB_CLASS_STILL_IMAGE 6 +#define USB_CLASS_PRINTER 7 +#define USB_CLASS_MASS_STORAGE 8 +#define USB_CLASS_HUB 9 +#define USB_CLASS_CDC_DATA 0x0a +#define USB_CLASS_CSCID 0x0b +#define USB_CLASS_CONTENT_SEC 0x0d +#define USB_CLASS_APP_SPEC 0xfe +#define USB_CLASS_VENDOR_SPEC 0xff + +#define USB_SUBCLASS_UNDEFINED 0 +#define USB_SUBCLASS_AUDIO_CONTROL 1 +#define USB_SUBCLASS_AUDIO_STREAMING 2 +#define USB_SUBCLASS_AUDIO_MIDISTREAMING 3 + +#define USB_DIR_OUT 0 +#define USB_DIR_IN 0x80 + +#define USB_TYPE_MASK (0x03 << 5) +#define USB_TYPE_STANDARD (0x00 << 5) +#define USB_TYPE_CLASS (0x01 << 5) +#define USB_TYPE_VENDOR (0x02 << 5) +#define USB_TYPE_RESERVED (0x03 << 5) + +#define USB_RECIP_MASK 0x1f +#define USB_RECIP_DEVICE 0x00 +#define USB_RECIP_INTERFACE 0x01 +#define USB_RECIP_ENDPOINT 0x02 +#define USB_RECIP_OTHER 0x03 + +#define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) +#define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) +#define InterfaceRequest \ + ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8) +#define InterfaceOutRequest \ + ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8) +#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8) +#define EndpointOutRequest \ + ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8) +#define ClassInterfaceRequest \ + ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8) +#define ClassInterfaceOutRequest \ + ((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8) + +#define USB_REQ_GET_STATUS 0x00 +#define USB_REQ_CLEAR_FEATURE 0x01 +#define USB_REQ_SET_FEATURE 0x03 +#define USB_REQ_SET_ADDRESS 0x05 +#define USB_REQ_GET_DESCRIPTOR 0x06 +#define USB_REQ_SET_DESCRIPTOR 0x07 +#define USB_REQ_GET_CONFIGURATION 0x08 +#define USB_REQ_SET_CONFIGURATION 0x09 +#define USB_REQ_GET_INTERFACE 0x0A +#define USB_REQ_SET_INTERFACE 0x0B +#define USB_REQ_SYNCH_FRAME 0x0C + +#define USB_DEVICE_SELF_POWERED 0 +#define USB_DEVICE_REMOTE_WAKEUP 1 + +#define USB_DT_DEVICE 0x01 +#define USB_DT_CONFIG 0x02 +#define USB_DT_STRING 0x03 +#define USB_DT_INTERFACE 0x04 +#define USB_DT_ENDPOINT 0x05 +#define USB_DT_DEVICE_QUALIFIER 0x06 +#define USB_DT_OTHER_SPEED_CONFIG 0x07 +#define USB_DT_DEBUG 0x0A +#define USB_DT_INTERFACE_ASSOC 0x0B +#define USB_DT_BOS 0x0F +#define USB_DT_DEVICE_CAPABILITY 0x10 +#define USB_DT_CS_INTERFACE 0x24 +#define USB_DT_CS_ENDPOINT 0x25 +#define USB_DT_ENDPOINT_COMPANION 0x30 + +#define USB_DEV_CAP_WIRELESS 0x01 +#define USB_DEV_CAP_USB2_EXT 0x02 +#define USB_DEV_CAP_SUPERSPEED 0x03 + +#define USB_ENDPOINT_XFER_CONTROL 0 +#define USB_ENDPOINT_XFER_ISOC 1 +#define USB_ENDPOINT_XFER_BULK 2 +#define USB_ENDPOINT_XFER_INT 3 +#define USB_ENDPOINT_XFER_INVALID 255 + +#define USB_INTERFACE_INVALID 255 + +typedef struct USBBus USBBus; +typedef struct USBBusOps USBBusOps; +typedef struct USBPort USBPort; +typedef struct USBDevice USBDevice; +typedef struct USBPacket USBPacket; +typedef struct USBCombinedPacket USBCombinedPacket; +typedef struct USBEndpoint USBEndpoint; + +typedef struct USBDesc USBDesc; +typedef struct USBDescID USBDescID; +typedef struct USBDescDevice USBDescDevice; +typedef struct USBDescConfig USBDescConfig; +typedef struct USBDescIfaceAssoc USBDescIfaceAssoc; +typedef struct USBDescIface USBDescIface; +typedef struct USBDescEndpoint USBDescEndpoint; +typedef struct USBDescOther USBDescOther; +typedef struct USBDescString USBDescString; + +struct USBDescString { + uint8_t index; + char *str; + QLIST_ENTRY(USBDescString) next; +}; + +#define USB_MAX_ENDPOINTS 15 +#define USB_MAX_INTERFACES 16 + +struct USBEndpoint { + uint8_t nr; + uint8_t pid; + uint8_t type; + uint8_t ifnum; + int max_packet_size; + bool pipeline; + bool halted; + USBDevice *dev; + QTAILQ_HEAD(, USBPacket) queue; +}; + +enum USBDeviceFlags { + USB_DEV_FLAG_FULL_PATH, + USB_DEV_FLAG_IS_HOST, +}; + +/* definition of a USB device */ +struct USBDevice { + DeviceState qdev; + USBPort *port; + char *port_path; + char *serial; + void *opaque; + uint32_t flags; + + /* Actual connected speed */ + int speed; + /* Supported speeds, not in info because it may be variable (hostdevs) */ + int speedmask; + uint8_t addr; + char product_desc[32]; + int auto_attach; + int attached; + + int32_t state; + uint8_t setup_buf[8]; + uint8_t data_buf[4096]; + int32_t remote_wakeup; + int32_t setup_state; + int32_t setup_len; + int32_t setup_index; + + USBEndpoint ep_ctl; + USBEndpoint ep_in[USB_MAX_ENDPOINTS]; + USBEndpoint ep_out[USB_MAX_ENDPOINTS]; + + QLIST_HEAD(, USBDescString) strings; + const USBDesc *usb_desc; /* Overrides class usb_desc if not NULL */ + const USBDescDevice *device; + + int configuration; + int ninterfaces; + int altsetting[USB_MAX_INTERFACES]; + const USBDescConfig *config; + const USBDescIface *ifaces[USB_MAX_INTERFACES]; +}; + +#define TYPE_USB_DEVICE "usb-device" +#define USB_DEVICE(obj) \ + OBJECT_CHECK(USBDevice, (obj), TYPE_USB_DEVICE) +#define USB_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(USBDeviceClass, (klass), TYPE_USB_DEVICE) +#define USB_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(USBDeviceClass, (obj), TYPE_USB_DEVICE) + +typedef struct USBDeviceClass { + DeviceClass parent_class; + + int (*init)(USBDevice *dev); + + /* + * Walk (enabled) downstream ports, check for a matching device. + * Only hubs implement this. + */ + USBDevice *(*find_device)(USBDevice *dev, uint8_t addr); + + /* + * Called when a packet is canceled. + */ + void (*cancel_packet)(USBDevice *dev, USBPacket *p); + + /* + * Called when device is destroyed. + */ + void (*handle_destroy)(USBDevice *dev); + + /* + * Attach the device + */ + void (*handle_attach)(USBDevice *dev); + + /* + * Reset the device + */ + void (*handle_reset)(USBDevice *dev); + + /* + * Process control request. + * Called from handle_packet(). + * + * Status gets stored in p->status, and if p->status == USB_RET_SUCCESS + * then the number of bytes transferred is stored in p->actual_length + */ + void (*handle_control)(USBDevice *dev, USBPacket *p, int request, int value, + int index, int length, uint8_t *data); + + /* + * Process data transfers (both BULK and ISOC). + * Called from handle_packet(). + * + * Status gets stored in p->status, and if p->status == USB_RET_SUCCESS + * then the number of bytes transferred is stored in p->actual_length + */ + void (*handle_data)(USBDevice *dev, USBPacket *p); + + void (*set_interface)(USBDevice *dev, int interface, + int alt_old, int alt_new); + + /* + * Called when the hcd is done queuing packets for an endpoint, only + * necessary for devices which can return USB_RET_ADD_TO_QUEUE. + */ + void (*flush_ep_queue)(USBDevice *dev, USBEndpoint *ep); + + /* + * Called by the hcd to let the device know the queue for an endpoint + * has been unlinked / stopped. Optional may be NULL. + */ + void (*ep_stopped)(USBDevice *dev, USBEndpoint *ep); + + const char *product_desc; + const USBDesc *usb_desc; +} USBDeviceClass; + +typedef struct USBPortOps { + void (*attach)(USBPort *port); + void (*detach)(USBPort *port); + /* + * This gets called when a device downstream from the device attached to + * the port (iow attached through a hub) gets detached. + */ + void (*child_detach)(USBPort *port, USBDevice *child); + void (*wakeup)(USBPort *port); + /* + * Note that port->dev will be different then the device from which + * the packet originated when a hub is involved. + */ + void (*complete)(USBPort *port, USBPacket *p); +} USBPortOps; + +/* USB port on which a device can be connected */ +struct USBPort { + USBDevice *dev; + int speedmask; + int hubcount; + char path[16]; + USBPortOps *ops; + void *opaque; + int index; /* internal port index, may be used with the opaque */ + QTAILQ_ENTRY(USBPort) next; +}; + +typedef void USBCallback(USBPacket * packet, void *opaque); + +typedef enum USBPacketState { + USB_PACKET_UNDEFINED = 0, + USB_PACKET_SETUP, + USB_PACKET_QUEUED, + USB_PACKET_ASYNC, + USB_PACKET_COMPLETE, + USB_PACKET_CANCELED, +} USBPacketState; + +/* Structure used to hold information about an active USB packet. */ +struct USBPacket { + /* Data fields for use by the driver. */ + int pid; + uint64_t id; + USBEndpoint *ep; + unsigned int stream; + QEMUIOVector iov; + uint64_t parameter; /* control transfers */ + bool short_not_ok; + bool int_req; + int status; /* USB_RET_* status code */ + int actual_length; /* Number of bytes actually transferred */ + /* Internal use by the USB layer. */ + USBPacketState state; + USBCombinedPacket *combined; + QTAILQ_ENTRY(USBPacket) queue; + QTAILQ_ENTRY(USBPacket) combined_entry; +}; + +struct USBCombinedPacket { + USBPacket *first; + QTAILQ_HEAD(packets_head, USBPacket) packets; + QEMUIOVector iov; +}; + +void usb_packet_init(USBPacket *p); +void usb_packet_set_state(USBPacket *p, USBPacketState state); +void usb_packet_check_state(USBPacket *p, USBPacketState expected); +void usb_packet_setup(USBPacket *p, int pid, + USBEndpoint *ep, unsigned int stream, + uint64_t id, bool short_not_ok, bool int_req); +void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len); +int usb_packet_map(USBPacket *p, QEMUSGList *sgl); +void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl); +void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes); +void usb_packet_skip(USBPacket *p, size_t bytes); +size_t usb_packet_size(USBPacket *p); +void usb_packet_cleanup(USBPacket *p); + +static inline bool usb_packet_is_inflight(USBPacket *p) +{ + return (p->state == USB_PACKET_QUEUED || + p->state == USB_PACKET_ASYNC); +} + +USBDevice *usb_find_device(USBPort *port, uint8_t addr); + +void usb_handle_packet(USBDevice *dev, USBPacket *p); +void usb_packet_complete(USBDevice *dev, USBPacket *p); +void usb_packet_complete_one(USBDevice *dev, USBPacket *p); +void usb_cancel_packet(USBPacket * p); + +void usb_ep_init(USBDevice *dev); +void usb_ep_reset(USBDevice *dev); +void usb_ep_dump(USBDevice *dev); +struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep); +uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep); +uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep); +void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type); +void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum); +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw); +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep); +void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled); +void usb_ep_set_halted(USBDevice *dev, int pid, int ep, bool halted); +USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, + uint64_t id); + +void usb_ep_combine_input_packets(USBEndpoint *ep); +void usb_combined_input_packet_complete(USBDevice *dev, USBPacket *p); +void usb_combined_packet_cancel(USBDevice *dev, USBPacket *p); + +void usb_attach(USBPort *port); +void usb_detach(USBPort *port); +void usb_port_reset(USBPort *port); +void usb_device_reset(USBDevice *dev); +void usb_wakeup(USBEndpoint *ep, unsigned int stream); +void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p); +int set_usb_string(uint8_t *buf, const char *str); + +/* usb-linux.c */ +USBDevice *usb_host_device_open(USBBus *bus, const char *devname); +void usb_host_info(Monitor *mon, const QDict *qdict); + +/* usb-bt.c */ +USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci); + +/* usb ports of the VM */ + +#define VM_USB_HUB_SIZE 8 + +/* usb-musb.c */ +enum musb_irq_source_e { + musb_irq_suspend = 0, + musb_irq_resume, + musb_irq_rst_babble, + musb_irq_sof, + musb_irq_connect, + musb_irq_disconnect, + musb_irq_vbus_request, + musb_irq_vbus_error, + musb_irq_rx, + musb_irq_tx, + musb_set_vbus, + musb_set_session, + /* Add new interrupts here */ + musb_irq_max, /* total number of interrupts defined */ +}; + +typedef struct MUSBState MUSBState; +MUSBState *musb_init(DeviceState *parent_device, int gpio_base); +void musb_reset(MUSBState *s); +uint32_t musb_core_intr_get(MUSBState *s); +void musb_core_intr_clear(MUSBState *s, uint32_t mask); +void musb_set_size(MUSBState *s, int epnum, int size, int is_tx); + +/* usb-bus.c */ + +#define TYPE_USB_BUS "usb-bus" +#define USB_BUS(obj) OBJECT_CHECK(USBBus, (obj), TYPE_USB_BUS) + +struct USBBus { + BusState qbus; + USBBusOps *ops; + int busnr; + int nfree; + int nused; + QTAILQ_HEAD(, USBPort) free; + QTAILQ_HEAD(, USBPort) used; + QTAILQ_ENTRY(USBBus) next; +}; + +struct USBBusOps { + int (*register_companion)(USBBus *bus, USBPort *ports[], + uint32_t portcount, uint32_t firstport); + void (*wakeup_endpoint)(USBBus *bus, USBEndpoint *ep, unsigned int stream); +}; + +void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host); +USBBus *usb_bus_find(int busnr); +void usb_legacy_register(const char *typename, const char *usbdevice_name, + USBDevice *(*usbdevice_init)(USBBus *bus, + const char *params)); +USBDevice *usb_create(USBBus *bus, const char *name); +USBDevice *usb_create_simple(USBBus *bus, const char *name); +USBDevice *usbdevice_create(const char *cmdline); +void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, + USBPortOps *ops, int speedmask); +int usb_register_companion(const char *masterbus, USBPort *ports[], + uint32_t portcount, uint32_t firstport, + void *opaque, USBPortOps *ops, int speedmask); +void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr); +void usb_unregister_port(USBBus *bus, USBPort *port); +int usb_claim_port(USBDevice *dev); +void usb_release_port(USBDevice *dev); +int usb_device_attach(USBDevice *dev); +int usb_device_detach(USBDevice *dev); +int usb_device_delete_addr(int busnr, int addr); + +static inline USBBus *usb_bus_from_device(USBDevice *d) +{ + return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus); +} + +extern const VMStateDescription vmstate_usb_device; + +#define VMSTATE_USB_DEVICE(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(USBDevice), \ + .vmsd = &vmstate_usb_device, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, USBDevice), \ +} + +USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr); + +void usb_device_cancel_packet(USBDevice *dev, USBPacket *p); + +void usb_device_handle_attach(USBDevice *dev); + +void usb_device_handle_reset(USBDevice *dev); + +void usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, + int val, int index, int length, uint8_t *data); + +void usb_device_handle_data(USBDevice *dev, USBPacket *p); + +void usb_device_set_interface(USBDevice *dev, int interface, + int alt_old, int alt_new); + +void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep); + +void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep); + +const char *usb_device_get_product_desc(USBDevice *dev); + +const USBDesc *usb_device_get_usb_desc(USBDevice *dev); + +int ehci_create_ich9_with_companions(PCIBus *bus, int slot); + +/* quirks.c */ + +/* In bulk endpoints are streaming data sources (iow behave like isoc eps) */ +#define USB_QUIRK_BUFFER_BULK_IN 0x01 +/* Bulk pkts in FTDI format, need special handling when combining packets */ +#define USB_QUIRK_IS_FTDI 0x02 + +int usb_get_quirks(uint16_t vendor_id, uint16_t product_id, + uint8_t interface_class, uint8_t interface_subclass, + uint8_t interface_protocol); + +#endif From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 20:33:52 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id B4BAE95D for ; Wed, 26 Jun 2013 20:33:52 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 96FAC1B5D for ; Wed, 26 Jun 2013 20:33:52 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QKXq7E050622 for ; Wed, 26 Jun 2013 20:33:52 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QKXqDV050615 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 20:33:52 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 20:33:52 GMT Message-Id: <201306262033.r5QKXqDV050615@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253558 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 20:33:52 -0000 Author: syuu Date: Wed Jun 26 20:33:52 2013 New Revision: 253558 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253558 Log: import qemu/queue.h Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h Added: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h Wed Jun 26 20:33:52 2013 (r253558) @@ -0,0 +1,414 @@ +/* $NetBSD: queue.h,v 1.52 2009/04/20 09:56:08 mschuett Exp $ */ + +/* + * QEMU version: Copy from netbsd, removed debug code, removed some of + * the implementations. Left in singly-linked lists, lists, simple + * queues, and tail queues. + */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef QEMU_SYS_QUEUE_H_ +#define QEMU_SYS_QUEUE_H_ + +/* + * This file defines four types of data structures: singly-linked lists, + * lists, simple queues, and tail queues. + * + * A singly-linked list is headed by a single forward pointer. The + * elements are singly linked for minimum space and pointer manipulation + * overhead at the expense of O(n) removal for arbitrary elements. New + * elements can be added to the list after an existing element or at the + * head of the list. Elements being removed from the head of the list + * should use the explicit macro for this purpose for optimum + * efficiency. A singly-linked list may only be traversed in the forward + * direction. Singly-linked lists are ideal for applications with large + * datasets and few or no removals or for implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + +#include "qemu/atomic.h" /* for smp_wmb() */ + +/* + * List definitions. + */ +#define QLIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define QLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define QLIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ +#define QLIST_INIT(head) do { \ + (head)->lh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define QLIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define QLIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define QLIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (/*CONSTCOND*/0) + +#define QLIST_INSERT_HEAD_RCU(head, elm, field) do { \ + (elm)->field.le_prev = &(head)->lh_first; \ + (elm)->field.le_next = (head)->lh_first; \ + smp_wmb(); /* fill elm before linking it */ \ + if ((head)->lh_first != NULL) { \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next; \ + } \ + (head)->lh_first = (elm); \ + smp_wmb(); \ +} while (/* CONSTCOND*/0) + +#define QLIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ +} while (/*CONSTCOND*/0) + +#define QLIST_FOREACH(var, head, field) \ + for ((var) = ((head)->lh_first); \ + (var); \ + (var) = ((var)->field.le_next)) + +#define QLIST_FOREACH_SAFE(var, head, field, next_var) \ + for ((var) = ((head)->lh_first); \ + (var) && ((next_var) = ((var)->field.le_next), 1); \ + (var) = (next_var)) + +/* + * List access methods. + */ +#define QLIST_EMPTY(head) ((head)->lh_first == NULL) +#define QLIST_FIRST(head) ((head)->lh_first) +#define QLIST_NEXT(elm, field) ((elm)->field.le_next) + + +/* + * Singly-linked List definitions. + */ +#define QSLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define QSLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define QSLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define QSLIST_INIT(head) do { \ + (head)->slh_first = NULL; \ +} while (/*CONSTCOND*/0) + +#define QSLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define QSLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define QSLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (/*CONSTCOND*/0) + +#define QSLIST_REMOVE_AFTER(slistelm, field) do { \ + (slistelm)->field.sle_next = \ + QSLIST_NEXT(QSLIST_NEXT((slistelm), field), field); \ +} while (/*CONSTCOND*/0) + +#define QSLIST_FOREACH(var, head, field) \ + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next) + +#define QSLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = QSLIST_FIRST((head)); \ + (var) && ((tvar) = QSLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List access methods. + */ +#define QSLIST_EMPTY(head) ((head)->slh_first == NULL) +#define QSLIST_FIRST(head) ((head)->slh_first) +#define QSLIST_NEXT(elm, field) ((elm)->field.sle_next) + + +/* + * Simple queue definitions. + */ +#define QSIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define QSIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define QSIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue functions. + */ +#define QSIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL)\ + (head)->sqh_last = &(head)->sqh_first; \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_REMOVE(head, elm, type, field) do { \ + if ((head)->sqh_first == (elm)) { \ + QSIMPLEQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->sqh_first; \ + while (curelm->field.sqe_next != (elm)) \ + curelm = curelm->field.sqe_next; \ + if ((curelm->field.sqe_next = \ + curelm->field.sqe_next->field.sqe_next) == NULL) \ + (head)->sqh_last = &(curelm)->field.sqe_next; \ + } \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_FOREACH(var, head, field) \ + for ((var) = ((head)->sqh_first); \ + (var); \ + (var) = ((var)->field.sqe_next)) + +#define QSIMPLEQ_FOREACH_SAFE(var, head, field, next) \ + for ((var) = ((head)->sqh_first); \ + (var) && ((next = ((var)->field.sqe_next)), 1); \ + (var) = (next)) + +#define QSIMPLEQ_CONCAT(head1, head2) do { \ + if (!QSIMPLEQ_EMPTY((head2))) { \ + *(head1)->sqh_last = (head2)->sqh_first; \ + (head1)->sqh_last = (head2)->sqh_last; \ + QSIMPLEQ_INIT((head2)); \ + } \ +} while (/*CONSTCOND*/0) + +#define QSIMPLEQ_LAST(head, type, field) \ + (QSIMPLEQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->sqh_last) - offsetof(struct type, field)))) + +/* + * Simple queue access methods. + */ +#define QSIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL) +#define QSIMPLEQ_FIRST(head) ((head)->sqh_first) +#define QSIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + + +/* + * Tail queue definitions. + */ +#define Q_TAILQ_HEAD(name, type, qual) \ +struct name { \ + qual type *tqh_first; /* first element */ \ + qual type *qual *tqh_last; /* addr of last next element */ \ +} +#define QTAILQ_HEAD(name, type) Q_TAILQ_HEAD(name, struct type,) + +#define QTAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define Q_TAILQ_ENTRY(type, qual) \ +struct { \ + qual type *tqe_next; /* next element */ \ + qual type *qual *tqe_prev; /* address of previous next element */\ +} +#define QTAILQ_ENTRY(type) Q_TAILQ_ENTRY(struct type,) + +/* + * Tail queue functions. + */ +#define QTAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ +} while (/*CONSTCOND*/0) + +#define QTAILQ_FOREACH(var, head, field) \ + for ((var) = ((head)->tqh_first); \ + (var); \ + (var) = ((var)->field.tqe_next)) + +#define QTAILQ_FOREACH_SAFE(var, head, field, next_var) \ + for ((var) = ((head)->tqh_first); \ + (var) && ((next_var) = ((var)->field.tqe_next), 1); \ + (var) = (next_var)) + +#define QTAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \ + (var); \ + (var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last))) + +/* + * Tail queue access methods. + */ +#define QTAILQ_EMPTY(head) ((head)->tqh_first == NULL) +#define QTAILQ_FIRST(head) ((head)->tqh_first) +#define QTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define QTAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +#define QTAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#endif /* !QEMU_SYS_QUEUE_H_ */ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 20:35:15 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3F42597D for ; Wed, 26 Jun 2013 20:35:15 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 2A5BF1B67 for ; Wed, 26 Jun 2013 20:35:15 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QKZFw3067110 for ; Wed, 26 Jun 2013 20:35:15 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QKZF0l067093 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 20:35:15 GMT (envelope-from syuu@FreeBSD.org) Date: Wed, 26 Jun 2013 20:35:15 GMT Message-Id: <201306262035.r5QKZF0l067093@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253559 - in soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb: . include/hw include/qemu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 20:35:15 -0000 Author: syuu Date: Wed Jun 26 20:35:14 2013 New Revision: 253559 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253559 Log: temporary comment out to make it able to compile Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c Wed Jun 26 20:33:52 2013 (r253558) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/core.c Wed Jun 26 20:35:14 2013 (r253559) @@ -23,10 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "qemu-common.h" +#include #include "hw/usb.h" -#include "qemu/iov.h" -#include "trace.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) void usb_attach(USBPort *port) { @@ -37,7 +37,7 @@ assert(dev->state == USB_STATE_NOTATTACHED); port->ops->attach(port); dev->state = USB_STATE_ATTACHED; - usb_device_handle_attach(dev); +// usb_device_handle_attach(dev); } void usb_detach(USBPort *port) @@ -68,7 +68,7 @@ dev->remote_wakeup = 0; dev->addr = 0; dev->state = USB_STATE_DEFAULT; - usb_device_handle_reset(dev); +// usb_device_handle_reset(dev); } void usb_wakeup(USBEndpoint *ep, unsigned int stream) @@ -101,12 +101,14 @@ { int request, value, index; +#if 0 if (p->iov.size != 8) { p->status = USB_RET_STALL; return; } usb_packet_copy(p, s->setup_buf, p->iov.size); +#endif p->actual_length = 0; s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6]; s->setup_index = 0; @@ -116,8 +118,8 @@ index = (s->setup_buf[5] << 8) | s->setup_buf[4]; if (s->setup_buf[0] & USB_DIR_IN) { - usb_device_handle_control(s, p, request, value, index, - s->setup_len, s->data_buf); +// usb_device_handle_control(s, p, request, value, index, +// s->setup_len, s->data_buf); if (p->status == USB_RET_ASYNC) { s->setup_state = SETUP_STATE_SETUP; } @@ -159,8 +161,8 @@ switch(s->setup_state) { case SETUP_STATE_ACK: if (!(s->setup_buf[0] & USB_DIR_IN)) { - usb_device_handle_control(s, p, request, value, index, - s->setup_len, s->data_buf); +// usb_device_handle_control(s, p, request, value, index, +// s->setup_len, s->data_buf); if (p->status == USB_RET_ASYNC) { return; } @@ -172,9 +174,11 @@ case SETUP_STATE_DATA: if (s->setup_buf[0] & USB_DIR_IN) { int len = s->setup_len - s->setup_index; +#if 0 if (len > p->iov.size) { len = p->iov.size; } +#endif usb_packet_copy(p, s->data_buf + s->setup_index, len); s->setup_index += len; if (s->setup_index >= s->setup_len) { @@ -208,9 +212,11 @@ case SETUP_STATE_DATA: if (!(s->setup_buf[0] & USB_DIR_IN)) { int len = s->setup_len - s->setup_index; +#if 0 if (len > p->iov.size) { len = p->iov.size; } +#endif usb_packet_copy(p, s->data_buf + s->setup_index, len); s->setup_index += len; if (s->setup_index >= s->setup_len) { @@ -255,8 +261,8 @@ usb_packet_copy(p, s->data_buf, s->setup_len); } - usb_device_handle_control(s, p, request, value, index, - s->setup_len, s->data_buf); +// usb_device_handle_control(s, p, request, value, index, +// s->setup_len, s->data_buf); if (p->status == USB_RET_ASYNC) { return; } @@ -313,7 +319,8 @@ /* XXX: fix overflow */ int set_usb_string(uint8_t *buf, const char *str) { - int len, i; + size_t len; + int i; uint8_t *q; q = buf; @@ -337,7 +344,8 @@ if (dev->addr == addr) { return dev; } - return usb_device_find_device(dev, addr); +// return usb_device_find_device(dev, addr); + return 0; } static void usb_process_one(USBPacket *p) @@ -372,7 +380,7 @@ } } else { /* data pipe */ - usb_device_handle_data(dev, p); +// usb_device_handle_data(dev, p); } } @@ -437,10 +445,12 @@ assert(QTAILQ_FIRST(&ep->queue) == p); assert(p->status != USB_RET_ASYNC && p->status != USB_RET_NAK); +#if 0 if (p->status != USB_RET_SUCCESS || (p->short_not_ok && (p->actual_length < p->iov.size))) { ep->halted = true; } +#endif usb_packet_set_state(p, USB_PACKET_COMPLETE); QTAILQ_REMOVE(&ep->queue, p, queue); dev->port->ops->complete(dev->port, p); @@ -487,14 +497,14 @@ usb_packet_set_state(p, USB_PACKET_CANCELED); QTAILQ_REMOVE(&p->ep->queue, p, queue); if (callback) { - usb_device_cancel_packet(p->ep->dev, p); +// usb_device_cancel_packet(p->ep->dev, p); } } void usb_packet_init(USBPacket *p) { - qemu_iovec_init(&p->iov, 1); +// qemu_iovec_init(&p->iov, 1); } static const char *usb_packet_state_name(USBPacketState state) @@ -523,24 +533,30 @@ } dev = p->ep->dev; bus = usb_bus_from_device(dev); +#if 0 trace_usb_packet_state_fault(bus->busnr, dev->port->path, p->ep->nr, p, usb_packet_state_name(p->state), usb_packet_state_name(expected)); +#endif assert(!"usb packet state check failed"); } void usb_packet_set_state(USBPacket *p, USBPacketState state) { if (p->ep) { +#if 0 USBDevice *dev = p->ep->dev; USBBus *bus = usb_bus_from_device(dev); trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p, usb_packet_state_name(p->state), usb_packet_state_name(state)); +#endif } else { +#if 0 trace_usb_packet_state_change(-1, "", -1, p, usb_packet_state_name(p->state), usb_packet_state_name(state)); +#endif } p->state = state; } @@ -550,7 +566,7 @@ uint64_t id, bool short_not_ok, bool int_req) { assert(!usb_packet_is_inflight(p)); - assert(p->iov.iov != NULL); +// assert(p->iov.iov != NULL); p->id = id; p->pid = pid; p->ep = ep; @@ -561,17 +577,18 @@ p->short_not_ok = short_not_ok; p->int_req = int_req; p->combined = NULL; - qemu_iovec_reset(&p->iov); +// qemu_iovec_reset(&p->iov); usb_packet_set_state(p, USB_PACKET_SETUP); } void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len) { - qemu_iovec_add(&p->iov, ptr, len); +// qemu_iovec_add(&p->iov, ptr, len); } void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes) { +#if 0 QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; assert(p->actual_length >= 0); @@ -589,10 +606,12 @@ abort(); } p->actual_length += bytes; +#endif } void usb_packet_skip(USBPacket *p, size_t bytes) { +#if 0 QEMUIOVector *iov = p->combined ? &p->combined->iov : &p->iov; assert(p->actual_length >= 0); @@ -601,17 +620,21 @@ iov_memset(iov->iov, iov->niov, p->actual_length, 0, bytes); } p->actual_length += bytes; +#endif } size_t usb_packet_size(USBPacket *p) { +#if 0 return p->combined ? p->combined->iov.size : p->iov.size; +#endif + return 0; } void usb_packet_cleanup(USBPacket *p) { assert(!usb_packet_is_inflight(p)); - qemu_iovec_destroy(&p->iov); +// qemu_iovec_destroy(&p->iov); } void usb_ep_reset(USBDevice *dev) Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Jun 26 20:33:52 2013 (r253558) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Wed Jun 26 20:35:14 2013 (r253559) @@ -25,13 +25,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "hw/hw.h" #include "hw/usb.h" -#include "hw/pci/pci.h" -#include "qemu/timer.h" -#include "qemu/iov.h" -#include "sysemu/dma.h" -#include "trace.h" //#define DEBUG //#define DEBUG_DUMP_DATA @@ -102,12 +96,12 @@ uint16_t device_id; uint8_t revision; uint8_t irq_pin; - int (*initfn)(PCIDevice *dev); +// int (*initfn)(PCIDevice *dev); bool unplug; }; struct UHCIPCIDeviceClass { - PCIDeviceClass parent_class; +// PCIDeviceClass parent_class; UHCIInfo info; }; @@ -143,8 +137,8 @@ } UHCIPort; struct UHCIState { - PCIDevice dev; - MemoryRegion io_bar; +// PCIDevice dev; +// MemoryRegion io_bar; USBBus bus; /* Note unused when we're a companion controller */ uint16_t cmd; /* cmd register */ uint16_t status; @@ -154,8 +148,8 @@ uint8_t sof_timing; uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */ int64_t expire_time; - QEMUTimer *frame_timer; - QEMUBH *bh; +// QEMUTimer *frame_timer; +// QEMUBH *bh; uint32_t frame_bytes; uint32_t frame_bandwidth; bool completions_only; @@ -206,7 +200,7 @@ { UHCIQueue *queue; - queue = g_new0(UHCIQueue, 1); +// queue = g_new0(UHCIQueue, 1); queue->uhci = s; queue->qh_addr = qh_addr; queue->token = uhci_queue_token(td); @@ -214,7 +208,7 @@ QTAILQ_INIT(&queue->asyncs); QTAILQ_INSERT_HEAD(&s->queues, queue, next); queue->valid = QH_VALID; - trace_usb_uhci_queue_add(queue->token); +// trace_usb_uhci_queue_add(queue->token); return queue; } @@ -229,9 +223,9 @@ } usb_device_ep_stopped(queue->ep->dev, queue->ep); - trace_usb_uhci_queue_del(queue->token, reason); +// trace_usb_uhci_queue_del(queue->token, reason); QTAILQ_REMOVE(&s->queues, queue, next); - g_free(queue); +// g_free(queue); } static UHCIQueue *uhci_queue_find(UHCIState *s, UHCI_TD *td) @@ -260,6 +254,7 @@ static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t td_addr) { +#if 0 UHCIAsync *async = g_new0(UHCIAsync, 1); async->queue = queue; @@ -268,40 +263,44 @@ trace_usb_uhci_packet_add(async->queue->token, async->td_addr); return async; +#endif + return 0; } static void uhci_async_free(UHCIAsync *async) { - trace_usb_uhci_packet_del(async->queue->token, async->td_addr); +// trace_usb_uhci_packet_del(async->queue->token, async->td_addr); usb_packet_cleanup(&async->packet); if (async->buf != async->static_buf) { - g_free(async->buf); +// g_free(async->buf); } - g_free(async); +// g_free(async); } static void uhci_async_link(UHCIAsync *async) { UHCIQueue *queue = async->queue; QTAILQ_INSERT_TAIL(&queue->asyncs, async, next); - trace_usb_uhci_packet_link_async(async->queue->token, async->td_addr); +// trace_usb_uhci_packet_link_async(async->queue->token, async->td_addr); } static void uhci_async_unlink(UHCIAsync *async) { UHCIQueue *queue = async->queue; QTAILQ_REMOVE(&queue->asyncs, async, next); - trace_usb_uhci_packet_unlink_async(async->queue->token, async->td_addr); +// trace_usb_uhci_packet_unlink_async(async->queue->token, async->td_addr); } static void uhci_async_cancel(UHCIAsync *async) { +#if 0 uhci_async_unlink(async); trace_usb_uhci_packet_cancel(async->queue->token, async->td_addr, async->done); if (!async->done) usb_cancel_packet(&async->packet); uhci_async_free(async); +#endif } /* @@ -379,11 +378,12 @@ } else { level = 0; } - qemu_set_irq(s->dev.irq[s->irq_pin], level); +// qemu_set_irq(s->dev.irq[s->irq_pin], level); } static void uhci_reset(void *opaque) { +#if 0 UHCIState *s = opaque; uint8_t *pci_conf; int i; @@ -413,8 +413,10 @@ uhci_async_cancel_all(s); qemu_bh_cancel(s->bh); uhci_update_irq(s); +#endif } +#if 0 static const VMStateDescription vmstate_uhci_port = { .name = "uhci port", .version_id = 1, @@ -425,18 +427,20 @@ VMSTATE_END_OF_LIST() } }; +#endif static int uhci_post_load(void *opaque, int version_id) { - UHCIState *s = opaque; +// UHCIState *s = opaque; if (version_id < 2) { - s->expire_time = qemu_get_clock_ns(vm_clock) + - (get_ticks_per_sec() / FRAME_TIMER_FREQ); +// s->expire_time = qemu_get_clock_ns(vm_clock) + +// (get_ticks_per_sec() / FRAME_TIMER_FREQ); } return 0; } +#if 0 static const VMStateDescription vmstate_uhci = { .name = "uhci", .version_id = 3, @@ -461,10 +465,12 @@ VMSTATE_END_OF_LIST() } }; +#endif static void uhci_port_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { +#if 0 UHCIState *s = opaque; trace_usb_uhci_mmio_writew(addr, val); @@ -555,10 +561,12 @@ } break; } +#endif } static uint64_t uhci_port_read(void *opaque, hwaddr addr, unsigned size) { +#if 0 UHCIState *s = opaque; uint32_t val; @@ -604,6 +612,8 @@ trace_usb_uhci_mmio_readw(addr, val); return val; +#endif + return 0; } /* signal resume if controller suspended */ @@ -698,17 +708,17 @@ static void uhci_read_td(UHCIState *s, UHCI_TD *td, uint32_t link) { - pci_dma_read(&s->dev, link & ~0xf, td, sizeof(*td)); - le32_to_cpus(&td->link); - le32_to_cpus(&td->ctrl); - le32_to_cpus(&td->token); - le32_to_cpus(&td->buffer); +// pci_dma_read(&s->dev, link & ~0xf, td, sizeof(*td)); +// le32_to_cpus(&td->link); +// le32_to_cpus(&td->ctrl); +// le32_to_cpus(&td->token); +// le32_to_cpus(&td->buffer); } static int uhci_handle_td_error(UHCIState *s, UHCI_TD *td, uint32_t td_addr, int status, uint32_t *int_mask) { - uint32_t queue_token = uhci_queue_token(td); +// uint32_t queue_token = uhci_queue_token(td); int ret; switch (status) { @@ -718,14 +728,14 @@ case USB_RET_STALL: td->ctrl |= TD_CTRL_STALL; - trace_usb_uhci_packet_complete_stall(queue_token, td_addr); +// trace_usb_uhci_packet_complete_stall(queue_token, td_addr); ret = TD_RESULT_NEXT_QH; break; case USB_RET_BABBLE: td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL; /* frame interrupted */ - trace_usb_uhci_packet_complete_babble(queue_token, td_addr); +// trace_usb_uhci_packet_complete_babble(queue_token, td_addr); ret = TD_RESULT_STOP_FRAME; break; @@ -734,7 +744,7 @@ default: td->ctrl |= TD_CTRL_TIMEOUT; td->ctrl &= ~(3 << TD_CTRL_ERROR_SHIFT); - trace_usb_uhci_packet_complete_error(queue_token, td_addr); +// trace_usb_uhci_packet_complete_error(queue_token, td_addr); ret = TD_RESULT_NEXT_QH; break; } @@ -775,19 +785,23 @@ *int_mask |= 0x01; if (pid == USB_TOKEN_IN) { - pci_dma_write(&s->dev, td->buffer, async->buf, len); +// pci_dma_write(&s->dev, td->buffer, async->buf, len); if ((td->ctrl & TD_CTRL_SPD) && len < max_len) { *int_mask |= 0x02; /* short packet: do not update QH */ +#if 0 trace_usb_uhci_packet_complete_shortxfer(async->queue->token, async->td_addr); +#endif return TD_RESULT_NEXT_QH; } } /* success */ +#if 0 trace_usb_uhci_packet_complete_success(async->queue->token, async->td_addr); +#endif return TD_RESULT_COMPLETE; } @@ -886,14 +900,14 @@ if (max_len <= sizeof(async->static_buf)) { async->buf = async->static_buf; } else { - async->buf = g_malloc(max_len); +// async->buf = g_malloc(max_len); } usb_packet_addbuf(&async->packet, async->buf, max_len); switch(pid) { case USB_TOKEN_OUT: case USB_TOKEN_SETUP: - pci_dma_read(&s->dev, td->buffer, async->buf, max_len); +// pci_dma_read(&s->dev, td->buffer, async->buf, max_len); usb_handle_packet(q->ep->dev, &async->packet); if (async->packet.status == USB_RET_SUCCESS) { async->packet.actual_length = max_len; @@ -928,7 +942,7 @@ static void uhci_async_complete(USBPort *port, USBPacket *packet) { - UHCIAsync *async = container_of(packet, UHCIAsync, packet); + UHCIAsync *async /*= container_of(packet, UHCIAsync, packet) */; UHCIState *s = async->queue->uhci; if (packet->status == USB_RET_REMOVE_FROM_QUEUE) { @@ -939,7 +953,7 @@ async->done = 1; /* Force processing of this packet *now*, needed for migration */ s->completions_only = true; - qemu_bh_schedule(s->bh); +// qemu_bh_schedule(s->bh); } static int is_valid(uint32_t link) @@ -999,7 +1013,7 @@ if (uhci_queue_token(&ptd) != q->token) { break; } - trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token); +// trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token); ret = uhci_handle_td(q->uhci, q, q->qh_addr, &ptd, plink, &int_mask); if (ret == TD_RESULT_ASYNC_CONT) { break; @@ -1013,7 +1027,7 @@ static void uhci_process_frame(UHCIState *s) { - uint32_t frame_addr, link, old_td_ctrl, val, int_mask; + uint32_t frame_addr, link, old_td_ctrl, /*val,*/ int_mask; uint32_t curr_qh, td_count = 0; int cnt, ret; UHCI_TD td; @@ -1022,8 +1036,8 @@ frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); - pci_dma_read(&s->dev, frame_addr, &link, 4); - le32_to_cpus(&link); +// pci_dma_read(&s->dev, frame_addr, &link, 4); +// le32_to_cpus(&link); int_mask = 0; curr_qh = 0; @@ -1034,12 +1048,12 @@ if (!s->completions_only && s->frame_bytes >= s->frame_bandwidth) { /* We've reached the usb 1.1 bandwidth, which is 1280 bytes/frame, stop processing */ - trace_usb_uhci_frame_stop_bandwidth(); +// trace_usb_uhci_frame_stop_bandwidth(); break; } if (is_qh(link)) { /* QH */ - trace_usb_uhci_qh_load(link & ~0xf); +// trace_usb_uhci_qh_load(link & ~0xf); if (qhdb_insert(&qhdb, link)) { /* @@ -1050,19 +1064,19 @@ * since we've been here last time. */ if (td_count == 0) { - trace_usb_uhci_frame_loop_stop_idle(); +// trace_usb_uhci_frame_loop_stop_idle(); break; } else { - trace_usb_uhci_frame_loop_continue(); +// trace_usb_uhci_frame_loop_continue(); td_count = 0; qhdb_reset(&qhdb); qhdb_insert(&qhdb, link); } } - pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); - le32_to_cpus(&qh.link); - le32_to_cpus(&qh.el_link); +// pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); +// le32_to_cpus(&qh.link); +// le32_to_cpus(&qh.el_link); if (!is_valid(qh.el_link)) { /* QH w/o elements */ @@ -1078,14 +1092,14 @@ /* TD */ uhci_read_td(s, &td, link); - trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token); +// trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token); old_td_ctrl = td.ctrl; ret = uhci_handle_td(s, NULL, curr_qh, &td, link, &int_mask); if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ - val = cpu_to_le32(td.ctrl); - pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); +// val = cpu_to_le32(td.ctrl); +// pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); } switch (ret) { @@ -1094,17 +1108,17 @@ case TD_RESULT_NEXT_QH: case TD_RESULT_ASYNC_CONT: - trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf); +// trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf); link = curr_qh ? qh.link : td.link; continue; case TD_RESULT_ASYNC_START: - trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf); +// trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf); link = curr_qh ? qh.link : td.link; continue; case TD_RESULT_COMPLETE: - trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf); +// trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf); link = td.link; td_count++; s->frame_bytes += (td.ctrl & 0x7ff) + 1; @@ -1112,8 +1126,8 @@ if (curr_qh) { /* update QH element link */ qh.el_link = link; - val = cpu_to_le32(qh.el_link); - pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); +// val = cpu_to_le32(qh.el_link); +// pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); if (!depth_first(link)) { /* done with this QH */ @@ -1145,15 +1159,15 @@ UHCIState *s = opaque; uint64_t t_now, t_last_run; int i, frames; - const uint64_t frame_t = get_ticks_per_sec() / FRAME_TIMER_FREQ; + const uint64_t frame_t /* = get_ticks_per_sec() / FRAME_TIMER_FREQ */; s->completions_only = false; - qemu_bh_cancel(s->bh); +// qemu_bh_cancel(s->bh); if (!(s->cmd & UHCI_CMD_RS)) { /* Full stop */ - trace_usb_uhci_schedule_stop(); - qemu_del_timer(s->frame_timer); +// trace_usb_uhci_schedule_stop(); +// qemu_del_timer(s->frame_timer); uhci_async_cancel_all(s); /* set hchalted bit in status - UHCI11D 2.1.2 */ s->status |= UHCI_STS_HCHALTED; @@ -1162,7 +1176,7 @@ /* We still store expire_time in our state, for migration */ t_last_run = s->expire_time - frame_t; - t_now = qemu_get_clock_ns(vm_clock); +// t_now = qemu_get_clock_ns(vm_clock); /* Process up to MAX_FRAMES_PER_TICK frames */ frames = (t_now - t_last_run) / frame_t; @@ -1178,7 +1192,7 @@ for (i = 0; i < frames; i++) { s->frame_bytes = 0; - trace_usb_uhci_frame_start(s->frnum); +// trace_usb_uhci_frame_start(s->frnum); uhci_async_validate_begin(s); uhci_process_frame(s); uhci_async_validate_end(s); @@ -1196,9 +1210,10 @@ } s->pending_int_mask = 0; - qemu_mod_timer(s->frame_timer, t_now + frame_t); +// qemu_mod_timer(s->frame_timer, t_now + frame_t); } +/* static const MemoryRegionOps uhci_ioport_ops = { .read = uhci_port_read, .write = uhci_port_write, @@ -1216,10 +1231,11 @@ .wakeup = uhci_wakeup, .complete = uhci_async_complete, }; +*/ +#if 0 static USBBusOps uhci_bus_ops = { }; - static int usb_uhci_common_initfn(PCIDevice *dev) { PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); @@ -1266,7 +1282,8 @@ return 0; } - +#endif +#if 0 static int usb_uhci_vt82c686b_initfn(PCIDevice *dev) { UHCIState *s = DO_UPCAST(UHCIState, dev, dev); @@ -1281,14 +1298,18 @@ return usb_uhci_common_initfn(dev); } +#endif +#if 0 static void usb_uhci_exit(PCIDevice *dev) { UHCIState *s = DO_UPCAST(UHCIState, dev, dev); memory_region_destroy(&s->io_bar); } +#endif +#if 0 static Property uhci_properties[] = { DEFINE_PROP_STRING("masterbus", UHCIState, masterbus), DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0), @@ -1296,7 +1317,9 @@ DEFINE_PROP_UINT32("maxframes", UHCIState, maxframes, 128), DEFINE_PROP_END_OF_LIST(), }; +#endif +#if 0 static void uhci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -1315,7 +1338,9 @@ dc->props = uhci_properties; u->info = *info; } +#endif +#if 0 static UHCIInfo uhci_info[] = { { .name = "piix3-usb-uhci", @@ -1383,9 +1408,11 @@ .unplug = false, } }; +#endif static void uhci_register_types(void) { +#if 0 TypeInfo uhci_type_info = { .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(UHCIState), @@ -1399,6 +1426,7 @@ uhci_type_info.class_data = uhci_info + i; type_register(&uhci_type_info); } +#endif } -type_init(uhci_register_types) +//type_init(uhci_register_types) Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Wed Jun 26 20:33:52 2013 (r253558) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/hw/usb.h Wed Jun 26 20:35:14 2013 (r253559) @@ -25,9 +25,15 @@ * THE SOFTWARE. */ -#include "hw/qdev.h" +#include +#include +#include +#include +#include #include "qemu/queue.h" +typedef uint64_t hwaddr; + /* Constants related to the USB / PCI interaction */ #define USB_SBRN 0x60 /* Serial Bus Release Number Register */ #define USB_RELEASE_1 0x10 /* USB 1.0 */ @@ -202,7 +208,7 @@ /* definition of a USB device */ struct USBDevice { - DeviceState qdev; +// DeviceState qdev; USBPort *port; char *port_path; char *serial; @@ -250,7 +256,7 @@ OBJECT_GET_CLASS(USBDeviceClass, (obj), TYPE_USB_DEVICE) typedef struct USBDeviceClass { - DeviceClass parent_class; +// DeviceClass parent_class; int (*init)(USBDevice *dev); @@ -364,7 +370,7 @@ uint64_t id; USBEndpoint *ep; unsigned int stream; - QEMUIOVector iov; +// QEMUIOVector iov; uint64_t parameter; /* control transfers */ bool short_not_ok; bool int_req; @@ -380,7 +386,7 @@ struct USBCombinedPacket { USBPacket *first; QTAILQ_HEAD(packets_head, USBPacket) packets; - QEMUIOVector iov; +// QEMUIOVector iov; }; void usb_packet_init(USBPacket *p); @@ -390,8 +396,8 @@ USBEndpoint *ep, unsigned int stream, uint64_t id, bool short_not_ok, bool int_req); void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len); -int usb_packet_map(USBPacket *p, QEMUSGList *sgl); -void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl); +//int usb_packet_map(USBPacket *p, QEMUSGList *sgl); +//void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl); void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes); void usb_packet_skip(USBPacket *p, size_t bytes); size_t usb_packet_size(USBPacket *p); @@ -440,10 +446,10 @@ /* usb-linux.c */ USBDevice *usb_host_device_open(USBBus *bus, const char *devname); -void usb_host_info(Monitor *mon, const QDict *qdict); +//void usb_host_info(Monitor *mon, const QDict *qdict); /* usb-bt.c */ -USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci); +//USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci); /* usb ports of the VM */ @@ -468,7 +474,7 @@ }; typedef struct MUSBState MUSBState; -MUSBState *musb_init(DeviceState *parent_device, int gpio_base); +//MUSBState *musb_init(DeviceState *parent_device, int gpio_base); void musb_reset(MUSBState *s); uint32_t musb_core_intr_get(MUSBState *s); void musb_core_intr_clear(MUSBState *s, uint32_t mask); @@ -480,7 +486,7 @@ #define USB_BUS(obj) OBJECT_CHECK(USBBus, (obj), TYPE_USB_BUS) struct USBBus { - BusState qbus; +// BusState qbus; USBBusOps *ops; int busnr; int nfree; @@ -496,7 +502,7 @@ void (*wakeup_endpoint)(USBBus *bus, USBEndpoint *ep, unsigned int stream); }; -void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host); +//void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host); USBBus *usb_bus_find(int busnr); void usb_legacy_register(const char *typename, const char *usbdevice_name, USBDevice *(*usbdevice_init)(USBBus *bus, @@ -519,10 +525,11 @@ static inline USBBus *usb_bus_from_device(USBDevice *d) { - return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus); +// return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus); + return NULL; } -extern const VMStateDescription vmstate_usb_device; +//extern const VMStateDescription vmstate_usb_device; #define VMSTATE_USB_DEVICE(_field, _state) { \ .name = (stringify(_field)), \ @@ -556,7 +563,7 @@ const USBDesc *usb_device_get_usb_desc(USBDevice *dev); -int ehci_create_ich9_with_companions(PCIBus *bus, int slot); +//int ehci_create_ich9_with_companions(PCIBus *bus, int slot); /* quirks.c */ Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h Wed Jun 26 20:33:52 2013 (r253558) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/include/qemu/queue.h Wed Jun 26 20:35:14 2013 (r253559) @@ -78,8 +78,6 @@ * For details on the use of these macros, see the queue(3) manual page. */ -#include "qemu/atomic.h" /* for smp_wmb() */ - /* * List definitions. */ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 21:14:28 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id ACD7DBAE for ; Wed, 26 Jun 2013 21:14:28 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9C6FF1D84 for ; Wed, 26 Jun 2013 21:14:28 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QLESgd029834 for ; Wed, 26 Jun 2013 21:14:28 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QLESBT029830 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 21:14:28 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 26 Jun 2013 21:14:28 GMT Message-Id: <201306262114.r5QLESBT029830@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253561 - in soc2013/dpl/head: contrib/bzip2 usr.bin/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 21:14:28 -0000 Author: dpl Date: Wed Jun 26 21:14:28 2013 New Revision: 253561 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253561 Log: Reimplemented sendfd and recvfd, now I know _where_ it breaks, but not why. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c soc2013/dpl/head/usr.bin/bzip2/Makefile Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Wed Jun 26 20:39:07 2013 (r253560) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Wed Jun 26 21:14:28 2013 (r253561) @@ -230,58 +230,72 @@ int sendfd(int s, int fd) { - char buf[1] = { 0 }; - struct iovec iov; - iov.iov_base = buf; - iov.iov_len = 1; - - struct msghdr msg; - char cms[CMSG_SPACE(sizeof(int))]; - bzero(&msg, sizeof msg); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)cms; - msg.msg_controllen = CMSG_LEN(sizeof(int)); - - struct cmsghdr *cmsg; - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmsg), &fd, sizeof(int)); - - printf("sendfd fd: %d\n", fd); - if((sendmsg(s, &msg, 0)) != (int)iov.iov_len) - return -1; - return 0; + printf("sendfd on socket:%d fd:%d\n",s,fd); + struct { + struct cmsghdr h; + int fd; + } buffer; + + struct msghdr msg; + char buf = 0; + struct iovec io; + struct cmsghdr *cmsg; + + io.iov_base = &buf; + io.iov_len = 1; + + bzero(&msg, sizeof msg); + msg.msg_iov = &io; + msg.msg_iovlen = 1; + msg.msg_control = &buffer; + msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = msg.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + printf("Gotten this far\n"); + /* Something breaks here */ + memcpy(CMSG_DATA(cmsg), fd, sizeof(int)); + if(sendmsg(s, &msg, 0) < 0) + return -1; + else + return 0; } int recvfd(int s) { - int fd; - struct cmsghdr *cmsg; - - char buf[1] = { 0 }; - struct iovec iov; - iov.iov_base = buf; - iov.iov_len = 1; - - struct msghdr msg; - char cms[CMSG_SPACE(sizeof(int))]; - msg.msg_name = 0; - msg.msg_namelen = 0; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)cms; - msg.msg_controllen = sizeof cms; - - if((recvmsg(s, &msg, 0)) <= 0) - return -1; - cmsg = CMSG_FIRSTHDR(&msg); - memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); - printf("recvfd fd: %d\n", fd); - return fd; + printf("recvfd on socket: %d\n",s); + struct { + struct cmsghdr h; + int fd; + } buffer; + char buf = 0; + struct iovec io; + struct msghdr msg; + struct cmsghdr *cmsg; + + io.iov_base = &buf; + io.iov_len = 1; + + bzero(&msg, sizeof msg); + msg.msg_iov = &io; + msg.msg_iovlen = 1; + msg.msg_control = &buffer; + msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = msg.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + /* Something breaks here */ + memcpy(CMSG_DATA(cmsg), -1, sizeof(int)); + printf("is this -1? %d", (int)CMSG_DATA(cmsg)); + + if(recvmsg(s, &msg, 0) < 0) + return -1 ; + return ((int *)CMSG_DATA(cmsg)); } #endif @@ -1387,7 +1401,7 @@ exit(exitValue); } - printf("About to fork()\n"); + printf("fork()\n"); /* Pass the limited file descriptors with a unix domain socket. */ switch( forkpid = fork() ) { case ( -1 ): @@ -1396,20 +1410,25 @@ exit(exitValue); case ( 0 ): - printf("Child\n"); - if ((infd = recvfd(sv[1])) <= 0){ + if ((close(sv[0])) < 0){ + fprintf ( stderr, "%s: Couldn't close fd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } + printf("About to recv infd\n"); + if ((infd = recvfd(sv[1])) < 0){ fprintf ( stderr, "%s: Couldn't get infd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); - } - - if ((outfd = recvfd(sv[1])) <= 0){ + } + if ((outfd = recvfd(sv[1])) < 0){ fprintf ( stderr, "%s: Couldn't get outfd: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); - } + } printf("Child: infd:%d, outfd:%d\n", infd, outfd); inStr = fdopen(infd, "rb"); outStr = fdopen(outfd, "wb"); @@ -1445,6 +1464,12 @@ default: printf("Parent: infd:%d, outfd:%d\n", infd, outfd); + if ((close(sv[1])) < 0){ + fprintf ( stderr, "%s: Couldn't close fd: %s.\n", + progName, strerror(errno) ); + setExit(1); + exit(exitValue); + } if (sendfd(sv[0], infd) < 0){ fprintf ( stderr, "%s: Couldn't send infd: %s.\n", progName, strerror(errno) ); Modified: soc2013/dpl/head/usr.bin/bzip2/Makefile ============================================================================== --- soc2013/dpl/head/usr.bin/bzip2/Makefile Wed Jun 26 20:39:07 2013 (r253560) +++ soc2013/dpl/head/usr.bin/bzip2/Makefile Wed Jun 26 21:14:28 2013 (r253561) @@ -5,6 +5,9 @@ PROG= bzip2 CFLAGS+= -D_FILE_OFFSET_BITS=64 +#TODO: Delete this. +CFLAGS+= -fno-color-diagnostics +CFLAGS+= -g WARNS?= 3 From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 23:29:00 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 1CB136DE for ; Wed, 26 Jun 2013 23:29:00 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id F2ACB1681 for ; Wed, 26 Jun 2013 23:28:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QNSxlT074030 for ; Wed, 26 Jun 2013 23:28:59 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QNSxi9074024 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 23:28:59 GMT (envelope-from mattbw@FreeBSD.org) Date: Wed, 26 Jun 2013 23:28:59 GMT Message-Id: <201306262328.r5QNSxi9074024@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253567 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 23:29:00 -0000 Author: mattbw Date: Wed Jun 26 23:28:59 2013 New Revision: 253567 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253567 Log: cleanup and formatting Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/actions/get-files.c soc2013/mattbw/backend/actions/get-repo-list.c soc2013/mattbw/backend/iterate.h Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/Makefile Wed Jun 26 23:28:59 2013 (r253567) @@ -22,5 +22,6 @@ CFLAGS+= `pkg-config --cflags ${PKGS}` CFLAGS+= -DPK_COMPILATION LDFLAGS+= `pkg-config --libs ${PKGS}` +CSTD?= c99 .include Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-details.c Wed Jun 26 23:28:59 2013 (r253567) @@ -30,11 +30,9 @@ #include "get-details.h" /* get_details_thread prototype */ static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; -static void get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean -get_details_for(gchar *package_id, - PkBackend *backend, - struct pkgdb *db); + +static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); +static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); /* * The thread that performs a GetDetails operation. Should be invoked by the @@ -43,14 +41,24 @@ gboolean get_details_thread(PkBackend *backend) { - return iterate_ids(backend, get_details_for); + return iterate_ids(backend, get_for); +} + +/* + * Look up and emit package details for the given PackageID, if it can be + * found. + */ +static gboolean +get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) +{ + return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); } /* * Emits the given package's details. To be used as an iterating function. */ static void -get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) { const char *description; const char *origin; @@ -72,13 +80,3 @@ www, flatsize); } - -/* - * Look up and emit package details for the given PackageID, if it can be - * found. - */ -gboolean -get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) -{ - return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_details_emit); -} Modified: soc2013/mattbw/backend/actions/get-files.c ============================================================================== --- soc2013/mattbw/backend/actions/get-files.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-files.c Wed Jun 26 23:28:59 2013 (r253567) @@ -24,19 +24,17 @@ #include "../db.h" /* db_query_from_id */ #include "../groups.h" /* group_from_origin */ +#include "../hash_traverse.h" /* HASH_FOR */ #include "../iterate.h" /* Package iteration */ #include "../licenses.h" /* license_from_pkg */ -#include "get-files.h" /* get_files_thread prototype */ +#include "get-files.h" /* get_files_thread prototype */ static const int FILE_NAME_STEP = 10; static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES; -static void get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean -get_files_for(gchar *package_id, - PkBackend *backend, - struct pkgdb *db); +static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); +static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); /* * The thread that performs a GetDetails operation. Should be invoked by the @@ -45,43 +43,40 @@ gboolean get_files_thread(PkBackend *backend) { - return iterate_ids(backend, get_files_for); + return iterate_ids(backend, get_for); } /* * Emits the given package's files. To be used as an iterating function. */ static void -get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) { struct pkg_file *file; - int err; + int err; - gchar **filenames; - gchar *joined_filenames; - gint capacity; - gint i; - - i = 0; - file = NULL; - /* Start off with a small array to hold the file names, - * and expand it if needs be. + gchar **filenames; + gchar *joined_filenames; + gint capacity; + gint i; + + /* + * Start off with a small array to hold the file names, and expand it + * if needs be. */ capacity = FILE_NAME_STEP; - filenames = g_new(gchar *, capacity); - do { - err = pkg_files(pkg, &file); - if (err == EPKG_OK) { - /* Out of capacity (leaving a NULL)? Expand the array. */ - if (i >= (capacity - 1)) { - capacity += FILE_NAME_STEP; - filenames = g_renew(gchar *, filenames, capacity); - } - - filenames[i] = g_strdup(pkg_file_path(file)); - i++; + i = 0; + file = NULL; + filenames = g_new(gchar *, capacity); + for (HASH_FOR(err, pkg_files, pkg, &file)) { + /* Out of capacity (leaving a NULL)? Expand the array. */ + if (i >= (capacity - 1)) { + capacity += FILE_NAME_STEP; + filenames = g_renew(gchar *, filenames, capacity); } - } while (err == EPKG_OK); + filenames[i] = g_strdup(pkg_file_path(file)); + i++; + } filenames[i] = NULL; joined_filenames = g_strjoinv(";", filenames); @@ -96,7 +91,7 @@ * found. */ gboolean -get_files_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) +get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) { - return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_files_emit); + return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); } Modified: soc2013/mattbw/backend/actions/get-repo-list.c ============================================================================== --- soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 23:28:59 2013 (r253567) @@ -23,6 +23,7 @@ #include "pkg.h" #include "../hash_traverse.h" /* HASH_FOR */ +#include "get-repo-list.h" /* Prototypes */ /* * The thread that performs a GetRepoList operation. Should be invoked by the Modified: soc2013/mattbw/backend/iterate.h ============================================================================== --- soc2013/mattbw/backend/iterate.h Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/iterate.h Wed Jun 26 23:28:59 2013 (r253567) @@ -26,9 +26,9 @@ #include "pkg.h" typedef void (*pkg_func_ptr) (struct pkg *pkg, - const char *id, - PkBackend *backend); -typedef gboolean (*ids_func_ptr) (gchar *id, PkBackend *backend, struct pkgdb *db); + const gchar *id, + PkBackend *backend); +typedef gboolean (*ids_func_ptr) (const gchar *id, PkBackend *backend, struct pkgdb *db); gboolean iterate_id_matches(struct pkgdb_it *iterator, @@ -39,6 +39,6 @@ const gchar *data, int fetch_flags, pkg_func_ptr iterate_f); -gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); +gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); #endif /* !_PKGNG_BACKEND_ITERATE_H_ */ From owner-svn-soc-all@FreeBSD.ORG Wed Jun 26 23:51:12 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id AC9C6253 for ; Wed, 26 Jun 2013 23:51:12 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 8F1851754 for ; Wed, 26 Jun 2013 23:51:12 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5QNpCWV078847 for ; Wed, 26 Jun 2013 23:51:12 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5QNpCnp078832 for svn-soc-all@FreeBSD.org; Wed, 26 Jun 2013 23:51:12 GMT (envelope-from mattbw@FreeBSD.org) Date: Wed, 26 Jun 2013 23:51:12 GMT Message-Id: <201306262351.r5QNpCnp078832@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253568 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jun 2013 23:51:12 -0000 Author: mattbw Date: Wed Jun 26 23:51:12 2013 New Revision: 253568 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253568 Log: start moving more generic string utilities out Added: soc2013/mattbw/backend/utils.c soc2013/mattbw/backend/utils.h Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/db.c soc2013/mattbw/backend/iterate.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Wed Jun 26 23:28:59 2013 (r253567) +++ soc2013/mattbw/backend/Makefile Wed Jun 26 23:51:12 2013 (r253568) @@ -2,7 +2,7 @@ LIB= pk_backend_pkgng SHLIB_MAJOR= 1 -SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c +SRCS= pk-backend-pkgng.c groups.c db.c licenses.c iterate.c utils.c SRCS+= actions/get-details.c actions/get-files.c actions/get-repo-list.c LIBDIR= /usr/local/lib/packagekit-backend Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Wed Jun 26 23:28:59 2013 (r253567) +++ soc2013/mattbw/backend/db.c Wed Jun 26 23:51:12 2013 (r253568) @@ -26,8 +26,7 @@ #include "db.h" /* prototypes */ #include "iterate.h" /* pkg_func_ptr */ - -static const char *null_if_empty(const char *in); +#include "utils.h" /* null_if_empty, split_id */ static gboolean db_query_split(const gchar *name, @@ -81,6 +80,8 @@ return success; } + + /* * Performs a package database query against a PackageID, and then hands the * matching results to an emitter function. @@ -88,38 +89,32 @@ * The exact type of query depends on the repository given. */ gboolean -db_query_with_id(const gchar *package_id, +db_query_with_id(const gchar *id, PkBackend *backend, struct pkgdb *db, int load_flags, pkg_func_ptr emitter) { - gchar **parts; gboolean success; + gchar **strv; + const gchar *name; + const gchar *version; + const gchar *arch; + const gchar *data; success = FALSE; + strv = NULL; - parts = pk_package_id_split(package_id); - if (parts == NULL) + success = split_id(id, &strv, &name, &version, &arch, &data); + if (success == FALSE) pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); else { - /* Parts of the package ID */ - const gchar *name; - const gchar *version; - const gchar *arch; - const gchar *data; - /* - * Make really really REALLY sure that the PackageID fields - * either have sensible data in them, or are NULL. + * If we got a repository name, then we want to make sure it + * corresponds to a real repository. */ - name = null_if_empty(parts[PK_PACKAGE_ID_NAME]); - version = null_if_empty(parts[PK_PACKAGE_ID_VERSION]); - arch = null_if_empty(parts[PK_PACKAGE_ID_ARCH]); - data = null_if_empty(parts[PK_PACKAGE_ID_DATA]); - /* * If the PackageID has a repository specified (even if it's * "installed" i.e. currently installed package), running @@ -151,7 +146,7 @@ pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found"); - g_strfreev(parts); + g_strfreev(strv); } return success; @@ -196,15 +191,3 @@ emitter); return success; } - -/* - * If the input pointer points to a string that is empty, return the null - * pointer; else pass through the pointer unmolested. - * - * This does NOT free anything! - */ -static const char * -null_if_empty(const char *in) -{ - return (in != NULL && strlen(in) == 0) ? NULL : in; -} Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Wed Jun 26 23:28:59 2013 (r253567) +++ soc2013/mattbw/backend/iterate.c Wed Jun 26 23:51:12 2013 (r253568) @@ -27,20 +27,20 @@ #include "db.h" /* open_remote_db */ #include "hash_traverse.h" /* HASH_FOR */ +#include "utils.h" /* string_match */ static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const gchar *arch, const gchar *data, gchar **match_id); -static gboolean string_match(const char *left, const char *right); gboolean iterate_id_matches(struct pkgdb_it *iterator, PkBackend *backend, - const gchar *name, - const gchar *version, - const gchar *arch, - const gchar *data, + const char *name, + const char *version, + const char *arch, + const char *data, int fetch_flags, pkg_func_ptr iterate_f) { @@ -86,8 +86,8 @@ } static gboolean -try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const - gchar *arch, const gchar *data, gchar **match_id) +try_id_match(struct pkg *pkg, const char *name, const char *version, const + char *arch, const char *data, char **match_id) { const char *p_arch; const char *p_data; @@ -130,24 +130,6 @@ } /* - * Checks two strings with strcmp and emits TRUE if they match. If either - * string is NULL, emit TRUE as well (this is so that missing PackageID - * elements trigger matches). - */ -static gboolean -string_match(const char *left, const char *right) -{ - int result; - - if (left == NULL || right == NULL) - result = TRUE; - else - result = (strcmp(left, right) == 0 ? TRUE : FALSE); - - return result; -} - -/* * Iterates over a set of PackageIDs provided for this job with a function. * * This provides each iterating function call with an open database connection Added: soc2013/mattbw/backend/utils.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/utils.c Wed Jun 26 23:51:12 2013 (r253568) @@ -0,0 +1,95 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* String/ID utilities. */ + +#include + +#include +#include "pk-backend.h" /* pk_package_id_split */ + +#include "utils.h" /* prototypes */ + +/* + * If the input pointer points to a string that is empty, return the null + * pointer; else pass through the pointer unmolested. + * + * This does NOT free anything! + */ +const char * +null_if_empty(const char *in) +{ + return (in != NULL && strlen(in) == 0) ? NULL : in; +} + +/* + * Splits a PackageID into its constituent parts, and returns both the split + * string vector (to be freed with g_strfreev later) and four pointers to its + * constituents (or NULL where they are empty strings). + * + * Returns FALSE on failure. + */ +gboolean +split_id(const char *id, + char ***strv_p, + const char **name_p, + const char **version_p, + const char **arch_p, + const char **data_p) +{ + int success; + char **strv; + + success = FALSE; + strv = pk_package_id_split(id); + if (strv != NULL) { + /* + * Make really really REALLY sure that the PackageID fields + * either have sensible data in them, or are NULL. + */ + *name_p = null_if_empty(strv[PK_PACKAGE_ID_NAME]); + *version_p = null_if_empty(strv[PK_PACKAGE_ID_VERSION]); + *arch_p = null_if_empty(strv[PK_PACKAGE_ID_ARCH]); + *data_p = null_if_empty(strv[PK_PACKAGE_ID_DATA]); + + *strv_p = strv; + success = TRUE; + } + return success; +} + +/* + * Checks two strings with strcmp and emits TRUE if they match. If either + * string is NULL, emit TRUE as well (this is so that missing PackageID + * elements trigger matches). + */ +gboolean +string_match(const char *left, const char *right) +{ + int result; + + if (left == NULL || right == NULL) + result = TRUE; + else + result = (strcmp(left, right) == 0 ? TRUE : FALSE); + + return result; +} Added: soc2013/mattbw/backend/utils.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/utils.h Wed Jun 26 23:51:12 2013 (r253568) @@ -0,0 +1,38 @@ +/*- + * + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _PKGNG_BACKEND_UTILS_H_ +#define _PKGNG_BACKEND_UTILS_H_ + +#include /* gboolean */ + +const char *null_if_empty(const char *in); +gboolean +split_id(const char *id, + char ***strv_p, + const char **name_p, + const char **version_p, + const char **arch_p, + const char **data_p); +gboolean string_match(const char *left, const char *right); + + +#endif /* !_PKGNG_BACKEND_DETAILS_H_ */ From owner-svn-soc-all@FreeBSD.ORG Thu Jun 27 00:09:03 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id BC947A30 for ; Thu, 27 Jun 2013 00:09:03 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 9ED4A1826 for ; Thu, 27 Jun 2013 00:09:03 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5R093GX007959 for ; Thu, 27 Jun 2013 00:09:03 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5R093gR007950 for svn-soc-all@FreeBSD.org; Thu, 27 Jun 2013 00:09:03 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 27 Jun 2013 00:09:03 GMT Message-Id: <201306270009.r5R093gR007950@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253581 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jun 2013 00:09:03 -0000 Author: mattbw Date: Thu Jun 27 00:09:03 2013 New Revision: 253581 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253581 Log: stop the screaming if a repository that does not exist is asked for, amongst other things Modified: soc2013/mattbw/backend/db.c soc2013/mattbw/backend/iterate.c Modified: soc2013/mattbw/backend/db.c ============================================================================== --- soc2013/mattbw/backend/db.c Wed Jun 26 23:53:54 2013 (r253580) +++ soc2013/mattbw/backend/db.c Thu Jun 27 00:09:03 2013 (r253581) @@ -95,27 +95,25 @@ int load_flags, pkg_func_ptr emitter) { - gboolean success; - gchar **strv; - const gchar *name; - const gchar *version; + gboolean query_success; + gboolean split_success; const gchar *arch; const gchar *data; + const gchar *name; + const gchar *version; + gchar **strv; - success = FALSE; + query_success = FALSE; + split_success = FALSE; strv = NULL; - success = split_id(id, &strv, &name, &version, &arch, &data); - if (success == FALSE) + split_success = split_id(id, &strv, &name, &version, &arch, &data); + if (split_success == FALSE) pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id"); else { /* - * If we got a repository name, then we want to make sure it - * corresponds to a real repository. - */ - /* * If the PackageID has a repository specified (even if it's * "installed" i.e. currently installed package), running * "get_details_query" directly should handle remote/local @@ -127,29 +125,29 @@ */ if (data == NULL) /* Try local database first. */ - success = db_query_split(name, - version, - arch, - "installed", - backend, - db, - load_flags, - emitter); - if (success == FALSE) - success = db_query_split(name, version, arch, data, + query_success = db_query_split(name, + version, + arch, + "installed", + backend, + db, + load_flags, + emitter); + if (query_success == FALSE) + query_success = db_query_split(name, version, arch, data, backend, db, load_flags, emitter); /* * Assume any error is due to not finding packages. At time * of writing this is true, but may change. */ - if (success == FALSE) + if (query_success == FALSE) pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "package not found"); g_strfreev(strv); } - return success; + return query_success; } /* @@ -174,13 +172,24 @@ gboolean success; success = FALSE; + it = NULL; /* Are we doing a local query? */ + /* + * If we got a repository name, then we want to make sure it + * corresponds to a real repository. + */ if (g_strcmp0(reponame, "installed") == 0) it = pkgdb_query(db, name, MATCH_EXACT); - else + else if (pkg_repo_find_ident(reponame) != NULL) it = pkgdb_rquery(db, name, MATCH_EXACT, reponame); - if (it) + else + pk_backend_error_code(backend, + PK_ERROR_ENUM_PACKAGE_NOT_FOUND, + "no such repository"); + + + if (it != NULL) success = iterate_id_matches(it, backend, name, Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Wed Jun 26 23:53:54 2013 (r253580) +++ soc2013/mattbw/backend/iterate.c Thu Jun 27 00:09:03 2013 (r253581) @@ -67,12 +67,12 @@ err = EPKG_FATAL; } else { for (HASH_FOR(err, pkgdb_it_next, iterator, &pkg, fetch_flags)) { - if (err == EPKG_OK && try_id_match(pkg, - name, - version, - arch, - data, - &match_id) == TRUE) { + if (try_id_match(pkg, + name, + version, + arch, + data, + &match_id) == TRUE) { found = TRUE; iterate_f(pkg, match_id, backend); } From owner-svn-soc-all@FreeBSD.ORG Thu Jun 27 00:35:59 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C9A55455 for ; Thu, 27 Jun 2013 00:35:59 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id AC2A01939 for ; Thu, 27 Jun 2013 00:35:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5R0ZxLv010920 for ; Thu, 27 Jun 2013 00:35:59 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5R0ZxhT010914 for svn-soc-all@FreeBSD.org; Thu, 27 Jun 2013 00:35:59 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 27 Jun 2013 00:35:59 GMT Message-Id: <201306270035.r5R0ZxhT010914@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253582 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jun 2013 00:35:59 -0000 Author: mattbw Date: Thu Jun 27 00:35:59 2013 New Revision: 253582 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253582 Log: fixed up the repository name matching for pkg1.1, via query test Modified: soc2013/mattbw/backend/iterate.c Modified: soc2013/mattbw/backend/iterate.c ============================================================================== --- soc2013/mattbw/backend/iterate.c Thu Jun 27 00:09:03 2013 (r253581) +++ soc2013/mattbw/backend/iterate.c Thu Jun 27 00:35:59 2013 (r253582) @@ -29,6 +29,8 @@ #include "hash_traverse.h" /* HASH_FOR */ #include "utils.h" /* string_match */ +static const char *get_repo_of(struct pkg *pkg); +static const char *get_repo_of_remote(struct pkg *pkg); static gboolean try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const gchar *arch, const gchar *data, gchar **match_id); @@ -61,18 +63,18 @@ if ((fetch_flags & PKG_LOAD_FILES) && g_strcmp0(data, "installed") != 0) { pk_backend_error_code(backend, - PK_ERROR_ENUM_CANNOT_GET_FILELIST, + PK_ERROR_ENUM_CANNOT_GET_FILELIST, "Cannot get files for non-installed package." - ); + ); err = EPKG_FATAL; } else { for (HASH_FOR(err, pkgdb_it_next, iterator, &pkg, fetch_flags)) { if (try_id_match(pkg, - name, - version, - arch, - data, - &match_id) == TRUE) { + name, + version, + arch, + data, + &match_id) == TRUE) { found = TRUE; iterate_f(pkg, match_id, backend); } @@ -85,6 +87,61 @@ return found; } +/* Gets the PackageKit repository name for the package. */ +static const char * +get_repo_of(struct pkg *pkg) +{ + const char *repo; + + switch (pkg_type(pkg)) { + case PKG_FILE: + repo = "local"; + break; + case PKG_INSTALLED: + repo = "installed"; + break; + case PKG_REMOTE: + repo = get_repo_of_remote(pkg); + break; + default: + repo = "unknown"; + break; + } + + return repo; +} + +/* + * Gets the PackageKit repository name for the (remote) package. + * + * Currently this is actually the pkgng repository ident. This might change. + * + * This does not need to be freed (possibly, TODO: check). + */ +static const char * +get_repo_of_remote(struct pkg *pkg) +{ + const char *repo; + const char *repo_name; + struct pkg_repo *repo_struct; + + repo = NULL; + + /* + * We can get the repo NAME directly, but we need the repo IDENT. + * Short of chopping bits of the string off in the assumption that + * the name is repo-IDENT, we'll have to grab it from the repo + * structure itself. + */ + pkg_get(pkg, PKG_REPONAME, &repo_name); + + repo_struct = pkg_repo_find_name(repo_name); + if (repo_struct) + repo = pkg_repo_ident(repo_struct); + + return repo; +} + static gboolean try_id_match(struct pkg *pkg, const char *name, const char *version, const char *arch, const char *data, char **match_id) @@ -99,20 +156,7 @@ PKG_NAME, &p_name, PKG_VERSION, &p_version); - switch (pkg_type(pkg)) { - case PKG_FILE: - p_data = "local"; - break; - case PKG_INSTALLED: - p_data = "installed"; - break; - case PKG_REMOTE: - pkg_get(pkg, PKG_REPONAME, &p_data); - break; - default: - p_data = "unknown"; - break; - } + p_data = get_repo_of(pkg); if (*match_id != NULL) g_free(*match_id); From owner-svn-soc-all@FreeBSD.ORG Thu Jun 27 00:36:22 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id A683246E for ; Thu, 27 Jun 2013 00:36:22 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 7F0C01940 for ; Thu, 27 Jun 2013 00:36:22 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5R0aMXZ015718 for ; Thu, 27 Jun 2013 00:36:22 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5R0aMsH015707 for svn-soc-all@FreeBSD.org; Thu, 27 Jun 2013 00:36:22 GMT (envelope-from mattbw@FreeBSD.org) Date: Thu, 27 Jun 2013 00:36:22 GMT Message-Id: <201306270036.r5R0aMsH015707@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253583 - in soc2013/mattbw: . tests/licence tests/query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jun 2013 00:36:22 -0000 Author: mattbw Date: Thu Jun 27 00:36:22 2013 New Revision: 253583 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253583 Log: here are those query tests, I really need to learn how to use svn Added: soc2013/mattbw/tests/licence/lictest.1 soc2013/mattbw/tests/query/ soc2013/mattbw/tests/query/Makefile soc2013/mattbw/tests/query/querytest.1 soc2013/mattbw/tests/query/querytest.c - copied, changed from r253430, soc2013/mattbw/querytest.c Deleted: soc2013/mattbw/querytest.c Added: soc2013/mattbw/tests/licence/lictest.1 ============================================================================== Added: soc2013/mattbw/tests/query/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/tests/query/Makefile Thu Jun 27 00:36:22 2013 (r253583) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +PROG= querytest +CFLAGS+= `pkgconf --cflags pkg` +LDFLAGS+= `pkgconf --libs pkg` + +.include Added: soc2013/mattbw/tests/query/querytest.1 ============================================================================== Copied and modified: soc2013/mattbw/tests/query/querytest.c (from r253430, soc2013/mattbw/querytest.c) ============================================================================== --- soc2013/mattbw/querytest.c Mon Jun 24 17:09:28 2013 (r253430, copy source) +++ soc2013/mattbw/tests/query/querytest.c Thu Jun 27 00:36:22 2013 (r253583) @@ -3,6 +3,7 @@ #include "pkg.h" void handle_it(struct pkgdb_it *it); +int getdb(struct pkgdb **db); int getdb(struct pkgdb **db) @@ -29,6 +30,11 @@ struct pkgdb *db; int err; + if (argc != 2) { + fprintf(stderr, "usage: %s packagename\n", argv[0]); + return 1; + } + db = NULL; err = pkg_init(NULL); @@ -40,12 +46,12 @@ if (err == EPKG_OK) { struct pkgdb_it *it; - it = pkgdb_query(db, "pkg", MATCH_EXACT); + it = pkgdb_query(db, argv[1], MATCH_EXACT); if (it == NULL) printf("no local matches!\n"); else handle_it(it); - it = pkgdb_rquery(db, "pkg", MATCH_EXACT, NULL); + it = pkgdb_rquery(db, argv[1], MATCH_EXACT, NULL); if (it == NULL) printf("no remote matches!\n"); else handle_it(it); From owner-svn-soc-all@FreeBSD.ORG Fri Jun 28 10:32:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 25E35E62 for ; Fri, 28 Jun 2013 10:32:36 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id F24FE107C for ; Fri, 28 Jun 2013 10:32:35 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5SAWZj8043526 for ; Fri, 28 Jun 2013 10:32:35 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5SAWZC7043524 for svn-soc-all@FreeBSD.org; Fri, 28 Jun 2013 10:32:35 GMT (envelope-from syuu@FreeBSD.org) Date: Fri, 28 Jun 2013 10:32:35 GMT Message-Id: <201306281032.r5SAWZC7043524@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253646 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2013 10:32:36 -0000 Author: syuu Date: Fri Jun 28 10:32:35 2013 New Revision: 253646 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253646 Log: cpu_to_le32/le32_to_cpus Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Fri Jun 28 09:55:00 2013 (r253645) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Fri Jun 28 10:32:35 2013 (r253646) @@ -26,6 +26,10 @@ * THE SOFTWARE. */ #include "hw/usb.h" +#include + +#define le32_to_cpus(x) le32toh(x) +#define cpu_to_le32(x) htole32(x) //#define DEBUG //#define DEBUG_DUMP_DATA @@ -709,10 +713,10 @@ static void uhci_read_td(UHCIState *s, UHCI_TD *td, uint32_t link) { // pci_dma_read(&s->dev, link & ~0xf, td, sizeof(*td)); -// le32_to_cpus(&td->link); -// le32_to_cpus(&td->ctrl); -// le32_to_cpus(&td->token); -// le32_to_cpus(&td->buffer); + le32_to_cpus(&td->link); + le32_to_cpus(&td->ctrl); + le32_to_cpus(&td->token); + le32_to_cpus(&td->buffer); } static int uhci_handle_td_error(UHCIState *s, UHCI_TD *td, uint32_t td_addr, @@ -1027,7 +1031,7 @@ static void uhci_process_frame(UHCIState *s) { - uint32_t frame_addr, link, old_td_ctrl, /*val,*/ int_mask; + uint32_t frame_addr, link, old_td_ctrl, *val, int_mask; uint32_t curr_qh, td_count = 0; int cnt, ret; UHCI_TD td; @@ -1037,7 +1041,7 @@ frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); // pci_dma_read(&s->dev, frame_addr, &link, 4); -// le32_to_cpus(&link); + le32_to_cpus(&link); int_mask = 0; curr_qh = 0; @@ -1075,8 +1079,8 @@ } // pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); -// le32_to_cpus(&qh.link); -// le32_to_cpus(&qh.el_link); + le32_to_cpus(&qh.link); + le32_to_cpus(&qh.el_link); if (!is_valid(qh.el_link)) { /* QH w/o elements */ @@ -1098,7 +1102,7 @@ ret = uhci_handle_td(s, NULL, curr_qh, &td, link, &int_mask); if (old_td_ctrl != td.ctrl) { /* update the status bits of the TD */ -// val = cpu_to_le32(td.ctrl); + val = cpu_to_le32(td.ctrl); // pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); } @@ -1126,7 +1130,7 @@ if (curr_qh) { /* update QH element link */ qh.el_link = link; -// val = cpu_to_le32(qh.el_link); + val = cpu_to_le32(qh.el_link); // pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); if (!depth_first(link)) { From owner-svn-soc-all@FreeBSD.ORG Fri Jun 28 10:58:07 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 70B6143F for ; Fri, 28 Jun 2013 10:58:07 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 60D6A116D for ; Fri, 28 Jun 2013 10:58:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5SAw7OZ041270 for ; Fri, 28 Jun 2013 10:58:07 GMT (envelope-from syuu@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5SAw7fs041268 for svn-soc-all@FreeBSD.org; Fri, 28 Jun 2013 10:58:07 GMT (envelope-from syuu@FreeBSD.org) Date: Fri, 28 Jun 2013 10:58:07 GMT Message-Id: <201306281058.r5SAw7fs041268@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to syuu@FreeBSD.org using -f From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253647 - soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2013 10:58:07 -0000 Author: syuu Date: Fri Jun 28 10:58:07 2013 New Revision: 253647 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253647 Log: uncomment out things Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Modified: soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c ============================================================================== --- soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Fri Jun 28 10:32:35 2013 (r253646) +++ soc2013/syuu/bhyve_usb/usr.sbin/bhyve/usb/hcd-uhci.c Fri Jun 28 10:58:07 2013 (r253647) @@ -27,6 +27,7 @@ */ #include "hw/usb.h" #include +#include #define le32_to_cpus(x) le32toh(x) #define cpu_to_le32(x) htole32(x) @@ -204,7 +205,7 @@ { UHCIQueue *queue; -// queue = g_new0(UHCIQueue, 1); + queue = (UHCIQueue *)calloc(sizeof(*queue), 1); queue->uhci = s; queue->qh_addr = qh_addr; queue->token = uhci_queue_token(td); @@ -229,7 +230,7 @@ // trace_usb_uhci_queue_del(queue->token, reason); QTAILQ_REMOVE(&s->queues, queue, next); -// g_free(queue); + free(queue); } static UHCIQueue *uhci_queue_find(UHCIState *s, UHCI_TD *td) @@ -258,17 +259,14 @@ static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t td_addr) { -#if 0 - UHCIAsync *async = g_new0(UHCIAsync, 1); + UHCIAsync *async = (UHCIAsync *)calloc(sizeof(*async), 1); async->queue = queue; async->td_addr = td_addr; usb_packet_init(&async->packet); - trace_usb_uhci_packet_add(async->queue->token, async->td_addr); +// trace_usb_uhci_packet_add(async->queue->token, async->td_addr); return async; -#endif - return 0; } static void uhci_async_free(UHCIAsync *async) @@ -276,9 +274,9 @@ // trace_usb_uhci_packet_del(async->queue->token, async->td_addr); usb_packet_cleanup(&async->packet); if (async->buf != async->static_buf) { -// g_free(async->buf); + free(async->buf); } -// g_free(async); + free(async); } static void uhci_async_link(UHCIAsync *async) @@ -297,14 +295,12 @@ static void uhci_async_cancel(UHCIAsync *async) { -#if 0 uhci_async_unlink(async); - trace_usb_uhci_packet_cancel(async->queue->token, async->td_addr, - async->done); +// trace_usb_uhci_packet_cancel(async->queue->token, async->td_addr, +// async->done); if (!async->done) usb_cancel_packet(&async->packet); uhci_async_free(async); -#endif } /* @@ -387,15 +383,14 @@ static void uhci_reset(void *opaque) { -#if 0 UHCIState *s = opaque; uint8_t *pci_conf; int i; UHCIPort *port; - trace_usb_uhci_reset(); +// trace_usb_uhci_reset(); - pci_conf = s->dev.config; + // pci_conf = s->dev.config; pci_conf[0x6a] = 0x01; /* usb clock */ pci_conf[0x6b] = 0x00; @@ -415,9 +410,8 @@ } uhci_async_cancel_all(s); - qemu_bh_cancel(s->bh); +// qemu_bh_cancel(s->bh); uhci_update_irq(s); -#endif } #if 0 @@ -435,12 +429,14 @@ static int uhci_post_load(void *opaque, int version_id) { -// UHCIState *s = opaque; +#if 0 + UHCIState *s = opaque; if (version_id < 2) { -// s->expire_time = qemu_get_clock_ns(vm_clock) + -// (get_ticks_per_sec() / FRAME_TIMER_FREQ); + s->expire_time = qemu_get_clock_ns(vm_clock) + + (get_ticks_per_sec() / FRAME_TIMER_FREQ); } +#endif return 0; } @@ -474,19 +470,18 @@ static void uhci_port_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { -#if 0 UHCIState *s = opaque; - trace_usb_uhci_mmio_writew(addr, val); +// trace_usb_uhci_mmio_writew(addr, val); switch(addr) { case 0x00: if ((val & UHCI_CMD_RS) && !(s->cmd & UHCI_CMD_RS)) { /* start frame processing */ - trace_usb_uhci_schedule_start(); - s->expire_time = qemu_get_clock_ns(vm_clock) + - (get_ticks_per_sec() / FRAME_TIMER_FREQ); - qemu_mod_timer(s->frame_timer, s->expire_time); +// trace_usb_uhci_schedule_start(); +// s->expire_time = qemu_get_clock_ns(vm_clock) + +// (get_ticks_per_sec() / FRAME_TIMER_FREQ); +// qemu_mod_timer(s->frame_timer, s->expire_time); s->status &= ~UHCI_STS_HCHALTED; } else if (!(val & UHCI_CMD_RS)) { s->status |= UHCI_STS_HCHALTED; @@ -565,12 +560,10 @@ } break; } -#endif } static uint64_t uhci_port_read(void *opaque, hwaddr addr, unsigned size) { -#if 0 UHCIState *s = opaque; uint32_t val; @@ -613,11 +606,9 @@ break; } - trace_usb_uhci_mmio_readw(addr, val); +// trace_usb_uhci_mmio_readw(addr, val); return val; -#endif - return 0; } /* signal resume if controller suspended */ @@ -904,7 +895,7 @@ if (max_len <= sizeof(async->static_buf)) { async->buf = async->static_buf; } else { -// async->buf = g_malloc(max_len); + async->buf = (uint8_t)malloc(max_len); } usb_packet_addbuf(&async->packet, async->buf, max_len); From owner-svn-soc-all@FreeBSD.ORG Sat Jun 29 13:33:23 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D022E382 for ; Sat, 29 Jun 2013 13:33:23 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B2D7E16BA for ; Sat, 29 Jun 2013 13:33:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5TDXNJB047302 for ; Sat, 29 Jun 2013 13:33:23 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5TDXNP3047293 for svn-soc-all@FreeBSD.org; Sat, 29 Jun 2013 13:33:23 GMT (envelope-from dpl@FreeBSD.org) Date: Sat, 29 Jun 2013 13:33:23 GMT Message-Id: <201306291333.r5TDXNP3047293@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253681 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jun 2013 13:33:23 -0000 Author: dpl Date: Sat Jun 29 13:33:23 2013 New Revision: 253681 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253681 Log: Trying hard with recvfd and sendfd. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 12:27:50 2013 (r253680) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 13:33:23 2013 (r253681) @@ -1,6 +1,6 @@ /*-----------------------------------------------------------*/ -/*--- A block-sorting, lossless compressor bzip2.c ---*/ +/*--- A block-sorting, lossless compressor bzip2.c ---*/ /*-----------------------------------------------------------*/ /* ------------------------------------------------------------------ @@ -23,7 +23,7 @@ Also works on 64-bit Unix boxes. This is the default. */ -#define BZ_UNIX 1 +#define BZ_UNIX 1 /*-- Win32, as seen by Jacob Navia's excellent @@ -56,8 +56,8 @@ #include #include "bzlib.h" -#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); } -#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); } +#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); } +#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); } #define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); } @@ -74,63 +74,64 @@ # include # include -# define PATH_SEP '/' -# define MY_LSTAT lstat -# define MY_STAT stat +# define PATH_SEP '/' +# define MY_LSTAT lstat +# define MY_STAT stat # define MY_S_ISREG S_ISREG # define MY_S_ISDIR S_ISDIR # define APPEND_FILESPEC(root, name) \ - root=snocString((root), (name)) + root=snocString((root), (name)) # define APPEND_FLAG(root, name) \ - root=snocString((root), (name)) + root=snocString((root), (name)) # define SET_BINARY_MODE(fd) /**/ -# ifdef __FreeBSD__ -# include -# if __FreeBSD_version >= 900041 -# define CAPSICUM 1 -# include -# include -# include -# include -# endif -# endif +# ifdef __FreeBSD__ +# include +# if __FreeBSD_version >= 900041 +# define CAPSICUM 1 +# include +# include +# include +# include +# endif +# endif + # ifdef __GNUC__ -# define NORETURN __attribute__ ((noreturn)) +# define NORETURN __attribute__ ((noreturn)) # else -# define NORETURN /**/ +# define NORETURN /**/ # endif # ifdef __DJGPP__ -# include -# include -# undef MY_LSTAT -# undef MY_STAT -# define MY_LSTAT stat -# define MY_STAT stat -# undef SET_BINARY_MODE -# define SET_BINARY_MODE(fd) \ - do { \ - int retVal = setmode ( fileno ( fd ), \ - O_BINARY ); \ - ERROR_IF_MINUS_ONE ( retVal ); \ - } while ( 0 ) +# include +# include +# undef MY_LSTAT +# undef MY_STAT +# define MY_LSTAT stat +# define MY_STAT stat +# undef SET_BINARY_MODE +# define SET_BINARY_MODE(fd) \ + do { \ + int retVal = setmode ( fileno ( fd ), \ + O_BINARY ); \ + ERROR_IF_MINUS_ONE ( retVal ); \ + } while ( 0 ) # endif # ifdef __CYGWIN__ -# include -# include -# undef SET_BINARY_MODE -# define SET_BINARY_MODE(fd) \ - do { \ - int retVal = setmode ( fileno ( fd ), \ - O_BINARY ); \ - ERROR_IF_MINUS_ONE ( retVal ); \ - } while ( 0 ) +# include +# include +# undef SET_BINARY_MODE +# define SET_BINARY_MODE(fd) \ + do { \ + int retVal = setmode ( fileno ( fd ), \ + O_BINARY ); \ + ERROR_IF_MINUS_ONE ( retVal ); \ + } while ( 0 ) # endif #endif /* BZ_UNIX */ @@ -141,25 +142,25 @@ # include # include -# define NORETURN /**/ -# define PATH_SEP '\\' -# define MY_LSTAT _stat -# define MY_STAT _stat +# define NORETURN /**/ +# define PATH_SEP '\\' +# define MY_LSTAT _stat +# define MY_STAT _stat # define MY_S_ISREG(x) ((x) & _S_IFREG) # define MY_S_ISDIR(x) ((x) & _S_IFDIR) # define APPEND_FLAG(root, name) \ - root=snocString((root), (name)) + root=snocString((root), (name)) -# define APPEND_FILESPEC(root, name) \ - root = snocString ((root), (name)) +# define APPEND_FILESPEC(root, name) \ + root = snocString ((root), (name)) -# define SET_BINARY_MODE(fd) \ - do { \ - int retVal = setmode ( fileno ( fd ), \ - O_BINARY ); \ - ERROR_IF_MINUS_ONE ( retVal ); \ - } while ( 0 ) +# define SET_BINARY_MODE(fd) \ + do { \ + int retVal = setmode ( fileno ( fd ), \ + O_BINARY ); \ + ERROR_IF_MINUS_ONE ( retVal ); \ + } while ( 0 ) #endif /* BZ_LCCWIN32 */ @@ -169,14 +170,14 @@ Some more stuff for all platforms :-) --*/ -typedef char Char; +typedef char Char; typedef unsigned char Bool; typedef unsigned char UChar; -typedef int Int32; -typedef unsigned int UInt32; -typedef short Int16; +typedef int Int32; +typedef unsigned int UInt32; +typedef short Int16; typedef unsigned short UInt16; - + #define True ((Bool)1) #define False ((Bool)0) @@ -188,24 +189,24 @@ /*---------------------------------------------------*/ -/*--- Misc (file handling) data decls ---*/ +/*--- Misc (file handling) data decls ---*/ /*---------------------------------------------------*/ Int32 verbosity; -Bool keepInputFiles, smallMode, deleteOutputOnInterrupt; -Bool forceOverwrite, testFailsExist, unzFailsExist, noisy; +Bool keepInputFiles, smallMode, deleteOutputOnInterrupt; +Bool forceOverwrite, testFailsExist, unzFailsExist, noisy; Int32 numFileNames, numFilesProcessed, blockSize100k; Int32 exitValue; /*-- source modes; F==file, I==stdin, O==stdout --*/ -#define SM_I2O 1 -#define SM_F2O 2 -#define SM_F2F 3 +#define SM_I2O 1 +#define SM_F2O 2 +#define SM_F2F 3 /*-- operation modes --*/ -#define OM_Z 1 -#define OM_UNZ 2 -#define OM_TEST 3 +#define OM_Z 1 +#define OM_UNZ 2 +#define OM_TEST 3 Int32 opMode; Int32 srcMode; @@ -213,12 +214,12 @@ #define FILE_NAME_LEN 1034 Int32 longestFileName; -Char inName [FILE_NAME_LEN]; -Char outName[FILE_NAME_LEN]; -Char tmpName[FILE_NAME_LEN]; -Char *progName; -Char progNameReally[FILE_NAME_LEN]; -FILE *outputHandleJustInCase; +Char inName [FILE_NAME_LEN]; +Char outName[FILE_NAME_LEN]; +Char tmpName[FILE_NAME_LEN]; +Char *progName; +Char progNameReally[FILE_NAME_LEN]; +FILE *outputHandleJustInCase; Int32 workFactor; #if CAPSICUM @@ -230,91 +231,82 @@ int sendfd(int s, int fd) { - printf("sendfd on socket:%d fd:%d\n",s,fd); - struct { - struct cmsghdr h; - int fd; - } buffer; - - struct msghdr msg; - char buf = 0; - struct iovec io; - struct cmsghdr *cmsg; - - io.iov_base = &buf; - io.iov_len = 1; - - bzero(&msg, sizeof msg); - msg.msg_iov = &io; - msg.msg_iovlen = 1; - msg.msg_control = &buffer; - msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = msg.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - printf("Gotten this far\n"); - /* Something breaks here */ - memcpy(CMSG_DATA(cmsg), fd, sizeof(int)); - if(sendmsg(s, &msg, 0) < 0) - return -1; - else - return 0; + printf("sendfd on socket:%d fd:%d\n",s,fd); + + struct msghdr msg; + struct cmsghdr *cmsg; + char buf = { 0 }; + struct iovec io[1]; + + io[0].iov_base = buf; + io[0].iov_len = 1; + + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_iov = io; + msg.msg_iovlen = 1; + msg.msg_control = cmsg; + msg.msg_controllen = CMSG_LEN(sizeof(int)); + + cmsg->cmsg_len = msg.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + *(int *)CMSG_DATA(cmsg) = fd; + /*Why does sendmsg set errno to 9 EBADF.*/ + if(sendmsg(s, &msg, 0) < 0) + return -1; + return 0; } int recvfd(int s) { - printf("recvfd on socket: %d\n",s); - struct { - struct cmsghdr h; - int fd; - } buffer; - char buf = 0; - struct iovec io; - struct msghdr msg; - struct cmsghdr *cmsg; - - io.iov_base = &buf; - io.iov_len = 1; - - bzero(&msg, sizeof msg); - msg.msg_iov = &io; - msg.msg_iovlen = 1; - msg.msg_control = &buffer; - msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int); - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_len = msg.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - /* Something breaks here */ - memcpy(CMSG_DATA(cmsg), -1, sizeof(int)); - printf("is this -1? %d", (int)CMSG_DATA(cmsg)); - - if(recvmsg(s, &msg, 0) < 0) - return -1 ; - return ((int *)CMSG_DATA(cmsg)); + printf("recvfd on socket:%d\n",s); + + int fd; + struct msghdr msg; + struct cmsghdr *cmsg; + char buf = { 0 }; + struct iovec io[1]; + + io[0].iov_base = buf; + io[0].iov_len = 1; + + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_iov = io; + msg.msg_iovlen = 1; + msg.msg_control = cmsg; + msg.msg_controllen = CMSG_LEN(sizeof(int)); + + cmsg->cmsg_len = msg.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + /*Why does sendmsg set errno to 9 EBADF.*/ + if(recvmsg(s, &msg, 0) < 0) + return -1; + fd = *(int *)CMSG_DATA(cmsg); + printf("recvfd() fd recieved: %d", fd); + return 0; } #endif -static void panic ( const Char* ) NORETURN; -static void ioError ( void ) NORETURN; -static void outOfMemory ( void ) NORETURN; -static void configError ( void ) NORETURN; -static void crcError ( void ) NORETURN; -static void cleanUpAndFail ( Int32 ) NORETURN; -static void compressedStreamEOF ( void ) NORETURN; - -static void copyFileName ( Char*, Char* ); -static void* myMalloc ( Int32 ); -static void applySavedFileAttrToOutputFile ( IntNative fd ); +static void panic ( const Char* ) NORETURN; +static void ioError ( void ) NORETURN; +static void outOfMemory ( void ) NORETURN; +static void configError ( void ) NORETURN; +static void crcError ( void ) NORETURN; +static void cleanUpAndFail ( Int32 ) NORETURN; +static void compressedStreamEOF ( void ) NORETURN; + +static void copyFileName ( Char*, Char* ); +static void* myMalloc ( Int32 ); +static void applySavedFileAttrToOutputFile ( IntNative fd ); /*---------------------------------------------------*/ -/*--- An implementation of 64-bit ints. Sigh. ---*/ +/*--- An implementation of 64-bit ints. Sigh. ---*/ /*--- Roll on widespread deployment of ANSI C9X ! ---*/ /*---------------------------------------------------*/ @@ -329,11 +321,11 @@ n->b[7] = (UChar)((hi32 >> 24) & 0xFF); n->b[6] = (UChar)((hi32 >> 16) & 0xFF); n->b[5] = (UChar)((hi32 >> 8) & 0xFF); - n->b[4] = (UChar) (hi32 & 0xFF); + n->b[4] = (UChar) (hi32 & 0xFF); n->b[3] = (UChar)((lo32 >> 24) & 0xFF); n->b[2] = (UChar)((lo32 >> 16) & 0xFF); n->b[1] = (UChar)((lo32 >> 8) & 0xFF); - n->b[0] = (UChar) (lo32 & 0xFF); + n->b[0] = (UChar) (lo32 & 0xFF); } @@ -344,8 +336,8 @@ double base = 1.0; double sum = 0.0; for (i = 0; i < 8; i++) { - sum += base * (double)(n->b[i]); - base *= 256.0; + sum += base * (double)(n->b[i]); + base *= 256.0; } return sum; } @@ -356,7 +348,7 @@ { Int32 i; for (i = 0; i < 8; i++) - if (n->b[i] != 0) return 0; + if (n->b[i] != 0) return 0; return 1; } @@ -369,9 +361,9 @@ Int32 i; rem = 0; for (i = 7; i >= 0; i--) { - tmp = rem * 256 + n->b[i]; - n->b[i] = tmp / 10; - rem = tmp % 10; + tmp = rem * 256 + n->b[i]; + n->b[i] = tmp / 10; + rem = tmp % 10; } return rem; } @@ -388,18 +380,18 @@ Int32 nBuf = 0; UInt64 n_copy = *n; do { - q = uInt64_qrm10 ( &n_copy ); - buf[nBuf] = q + '0'; - nBuf++; + q = uInt64_qrm10 ( &n_copy ); + buf[nBuf] = q + '0'; + nBuf++; } while (!uInt64_isZero(&n_copy)); outbuf[nBuf] = 0; for (i = 0; i < nBuf; i++) - outbuf[i] = buf[nBuf-i-1]; + outbuf[i] = buf[nBuf-i-1]; } /*---------------------------------------------------*/ -/*--- Processing of complete files and streams ---*/ +/*--- Processing of complete files and streams ---*/ /*---------------------------------------------------*/ /*---------------------------------------------*/ @@ -431,36 +423,36 @@ if (ferror(zStream)) goto errhandler_io; bzf = BZ2_bzWriteOpen ( &bzerr, zStream, - blockSize100k, verbosity, workFactor ); + blockSize100k, verbosity, workFactor ); if (bzerr != BZ_OK) goto errhandler; if (verbosity >= 2) fprintf ( stderr, "\n" ); while (True) { - if (myfeof(stream)) break; - nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream ); - if (ferror(stream)) goto errhandler_io; - if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf ); - if (bzerr != BZ_OK) goto errhandler; + if (myfeof(stream)) break; + nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream ); + if (ferror(stream)) goto errhandler_io; + if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf ); + if (bzerr != BZ_OK) goto errhandler; } BZ2_bzWriteClose64 ( &bzerr, bzf, 0, - &nbytes_in_lo32, &nbytes_in_hi32, - &nbytes_out_lo32, &nbytes_out_hi32 ); + &nbytes_in_lo32, &nbytes_in_hi32, + &nbytes_out_lo32, &nbytes_out_hi32 ); if (bzerr != BZ_OK) goto errhandler; if (ferror(zStream)) goto errhandler_io; ret = fflush ( zStream ); if (ret == EOF) goto errhandler_io; if (zStream != stdout) { - Int32 fd = fileno ( zStream ); - if (fd < 0) goto errhandler_io; - applySavedFileAttrToOutputFile ( fd ); - ret = fclose ( zStream ); - outputHandleJustInCase = NULL; - if (ret == EOF) goto errhandler_io; + Int32 fd = fileno ( zStream ); + if (fd < 0) goto errhandler_io; + applySavedFileAttrToOutputFile ( fd ); + ret = fclose ( zStream ); + outputHandleJustInCase = NULL; + if (ret == EOF) goto errhandler_io; } outputHandleJustInCase = NULL; if (ferror(stream)) goto errhandler_io; @@ -468,16 +460,16 @@ if (ret == EOF) goto errhandler_io; if (verbosity >= 1) { - if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) { + if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) { fprintf ( stderr, " no data compressed.\n"); - } else { + } else { Char buf_nin[32], buf_nout[32]; UInt64 nbytes_in, nbytes_out; double nbytes_in_d, nbytes_out_d; uInt64_from_UInt32s ( &nbytes_in, - nbytes_in_lo32, nbytes_in_hi32 ); + nbytes_in_lo32, nbytes_in_hi32 ); uInt64_from_UInt32s ( &nbytes_out, - nbytes_out_lo32, nbytes_out_hi32 ); + nbytes_out_lo32, nbytes_out_hi32 ); nbytes_in_d = uInt64_to_double ( &nbytes_in ); nbytes_out_d = uInt64_to_double ( &nbytes_out ); uInt64_toAscii ( buf_nin, &nbytes_in ); @@ -490,25 +482,25 @@ buf_nin, buf_nout ); - } + } } return; errhandler: BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1, - &nbytes_in_lo32, &nbytes_in_hi32, - &nbytes_out_lo32, &nbytes_out_hi32 ); + &nbytes_in_lo32, &nbytes_in_hi32, + &nbytes_out_lo32, &nbytes_out_hi32 ); switch (bzerr) { - case BZ_CONFIG_ERROR: - configError(); break; - case BZ_MEM_ERROR: - outOfMemory (); break; - case BZ_IO_ERROR: - errhandler_io: - ioError(); break; - default: - panic ( "compress:unexpected error" ); + case BZ_CONFIG_ERROR: + configError(); break; + case BZ_MEM_ERROR: + outOfMemory (); break; + case BZ_IO_ERROR: + errhandler_io: + ioError(); break; + default: + panic ( "compress:unexpected error" ); } panic ( "compress:end" ); @@ -540,40 +532,40 @@ while (True) { - bzf = BZ2_bzReadOpen ( - &bzerr, zStream, verbosity, - (int)smallMode, unused, nUnused - ); - if (bzf == NULL || bzerr != BZ_OK) goto errhandler; - streamNo++; - - while (bzerr == BZ_OK) { - nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); - if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat; - if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0) - fwrite ( obuf, sizeof(UChar), nread, stream ); - if (ferror(stream)) goto errhandler_io; - } - if (bzerr != BZ_STREAM_END) goto errhandler; + bzf = BZ2_bzReadOpen ( + &bzerr, zStream, verbosity, + (int)smallMode, unused, nUnused + ); + if (bzf == NULL || bzerr != BZ_OK) goto errhandler; + streamNo++; - BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); - if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); + while (bzerr == BZ_OK) { + nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); + if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat; + if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0) + fwrite ( obuf, sizeof(UChar), nread, stream ); + if (ferror(stream)) goto errhandler_io; + } + if (bzerr != BZ_STREAM_END) goto errhandler; - unusedTmp = (UChar*)unusedTmpV; - for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; + BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); + if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); - BZ2_bzReadClose ( &bzerr, bzf ); - if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); + unusedTmp = (UChar*)unusedTmpV; + for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; - if (nUnused == 0 && myfeof(zStream)) break; + BZ2_bzReadClose ( &bzerr, bzf ); + if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" ); + + if (nUnused == 0 && myfeof(zStream)) break; } closeok: if (ferror(zStream)) goto errhandler_io; if (stream != stdout) { - Int32 fd = fileno ( stream ); - if (fd < 0) goto errhandler_io; - applySavedFileAttrToOutputFile ( fd ); + Int32 fd = fileno ( stream ); + if (fd < 0) goto errhandler_io; + applySavedFileAttrToOutputFile ( fd ); } ret = fclose ( zStream ); if (ret == EOF) goto errhandler_io; @@ -582,55 +574,55 @@ ret = fflush ( stream ); if (ret != 0) goto errhandler_io; if (stream != stdout) { - ret = fclose ( stream ); - outputHandleJustInCase = NULL; - if (ret == EOF) goto errhandler_io; + ret = fclose ( stream ); + outputHandleJustInCase = NULL; + if (ret == EOF) goto errhandler_io; } outputHandleJustInCase = NULL; - if (verbosity >= 2) fprintf ( stderr, "\n " ); + if (verbosity >= 2) fprintf ( stderr, "\n " ); return True; trycat: if (forceOverwrite) { - rewind(zStream); - while (True) { - if (myfeof(zStream)) break; - nread = fread ( obuf, sizeof(UChar), 5000, zStream ); - if (ferror(zStream)) goto errhandler_io; - if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream ); - if (ferror(stream)) goto errhandler_io; - } - goto closeok; + rewind(zStream); + while (True) { + if (myfeof(zStream)) break; + nread = fread ( obuf, sizeof(UChar), 5000, zStream ); + if (ferror(zStream)) goto errhandler_io; + if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream ); + if (ferror(stream)) goto errhandler_io; + } + goto closeok; } errhandler: BZ2_bzReadClose ( &bzerr_dummy, bzf ); switch (bzerr) { - case BZ_CONFIG_ERROR: - configError(); break; - case BZ_IO_ERROR: - errhandler_io: - ioError(); break; - case BZ_DATA_ERROR: - crcError(); - case BZ_MEM_ERROR: - outOfMemory(); - case BZ_UNEXPECTED_EOF: - compressedStreamEOF(); - case BZ_DATA_ERROR_MAGIC: - if (zStream != stdin) fclose(zStream); - if (stream != stdout) fclose(stream); - if (streamNo == 1) { - return False; - } else { - if (noisy) - fprintf ( stderr, - "\n%s: %s: trailing garbage after EOF ignored\n", - progName, inName ); - return True; - } - default: - panic ( "decompress:unexpected error" ); + case BZ_CONFIG_ERROR: + configError(); break; + case BZ_IO_ERROR: + errhandler_io: + ioError(); break; + case BZ_DATA_ERROR: + crcError(); + case BZ_MEM_ERROR: + outOfMemory(); + case BZ_UNEXPECTED_EOF: + compressedStreamEOF(); + case BZ_DATA_ERROR_MAGIC: + if (zStream != stdin) fclose(zStream); + if (stream != stdout) fclose(stream); + if (streamNo == 1) { + return False; + } else { + if (noisy) + fprintf ( stderr, + "\n%s: %s: trailing garbage after EOF ignored\n", + progName, inName ); + return True; + } + default: + panic ( "decompress:unexpected error" ); } panic ( "decompress:end" ); @@ -658,28 +650,28 @@ while (True) { - bzf = BZ2_bzReadOpen ( - &bzerr, zStream, verbosity, - (int)smallMode, unused, nUnused - ); - if (bzf == NULL || bzerr != BZ_OK) goto errhandler; - streamNo++; - - while (bzerr == BZ_OK) { - nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); - if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler; - } - if (bzerr != BZ_STREAM_END) goto errhandler; + bzf = BZ2_bzReadOpen ( + &bzerr, zStream, verbosity, + (int)smallMode, unused, nUnused + ); + if (bzf == NULL || bzerr != BZ_OK) goto errhandler; + streamNo++; - BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); - if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); + while (bzerr == BZ_OK) { + nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 ); + if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler; + } + if (bzerr != BZ_STREAM_END) goto errhandler; + + BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused ); + if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); - unusedTmp = (UChar*)unusedTmpV; - for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; + unusedTmp = (UChar*)unusedTmpV; + for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i]; - BZ2_bzReadClose ( &bzerr, bzf ); - if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); - if (nUnused == 0 && myfeof(zStream)) break; + BZ2_bzReadClose ( &bzerr, bzf ); + if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" ); + if (nUnused == 0 && myfeof(zStream)) break; } @@ -687,43 +679,43 @@ ret = fclose ( zStream ); if (ret == EOF) goto errhandler_io; - if (verbosity >= 2) fprintf ( stderr, "\n " ); + if (verbosity >= 2) fprintf ( stderr, "\n " ); return True; errhandler: BZ2_bzReadClose ( &bzerr_dummy, bzf ); if (verbosity == 0) - fprintf ( stderr, "%s: %s: ", progName, inName ); + fprintf ( stderr, "%s: %s: ", progName, inName ); switch (bzerr) { - case BZ_CONFIG_ERROR: - configError(); break; - case BZ_IO_ERROR: - errhandler_io: - ioError(); break; - case BZ_DATA_ERROR: - fprintf ( stderr, - "data integrity (CRC) error in data\n" ); + case BZ_CONFIG_ERROR: + configError(); break; + case BZ_IO_ERROR: + errhandler_io: + ioError(); break; + case BZ_DATA_ERROR: + fprintf ( stderr, + "data integrity (CRC) error in data\n" ); + return False; + case BZ_MEM_ERROR: + outOfMemory(); + case BZ_UNEXPECTED_EOF: + fprintf ( stderr, + "file ends unexpectedly\n" ); + return False; + case BZ_DATA_ERROR_MAGIC: + if (zStream != stdin) fclose(zStream); + if (streamNo == 1) { + fprintf ( stderr, + "bad magic number (file not created by bzip2)\n" ); return False; - case BZ_MEM_ERROR: - outOfMemory(); - case BZ_UNEXPECTED_EOF: - fprintf ( stderr, - "file ends unexpectedly\n" ); - return False; - case BZ_DATA_ERROR_MAGIC: - if (zStream != stdin) fclose(zStream); - if (streamNo == 1) { - fprintf ( stderr, - "bad magic number (file not created by bzip2)\n" ); - return False; - } else { - if (noisy) - fprintf ( stderr, - "trailing garbage after EOF ignored\n" ); - return True; - } - default: - panic ( "test:unexpected error" ); + } else { + if (noisy) + fprintf ( stderr, + "trailing garbage after EOF ignored\n" ); + return True; + } + default: + panic ( "test:unexpected error" ); } panic ( "test:end" ); @@ -732,7 +724,7 @@ /*---------------------------------------------------*/ -/*--- Error [non-] handling grunge ---*/ +/*--- Error [non-] handling grunge ---*/ /*---------------------------------------------------*/ /*---------------------------------------------*/ @@ -749,12 +741,12 @@ { if (noisy) fprintf ( - stderr, - "\nIt is possible that the compressed file(s) have become corrupted.\n" - "You can use the -tvv option to test integrity of such files.\n\n" - "You can use the `bzip2recover' program to attempt to recover\n" - "data from undamaged sections of corrupted files.\n\n" - ); + stderr, + "\nIt is possible that the compressed file(s) have become corrupted.\n" + "You can use the -tvv option to test integrity of such files.\n\n" + "You can use the `bzip2recover' program to attempt to recover\n" + "data from undamaged sections of corrupted files.\n\n" + ); } @@ -764,9 +756,9 @@ { if (noisy) fprintf ( - stderr, - "\tInput file = %s, output file = %s\n", - inName, outName + stderr, + "\tInput file = %s, output file = %s\n", + inName, outName ); } @@ -775,55 +767,55 @@ static void cleanUpAndFail ( Int32 ec ) { - IntNative retVal; + IntNative retVal; struct MY_STAT statBuf; if ( srcMode == SM_F2F - && opMode != OM_TEST - && deleteOutputOnInterrupt ) { + && opMode != OM_TEST + && deleteOutputOnInterrupt ) { - /* Check whether input file still exists. Delete output file - only if input exists to avoid loss of data. Joerg Prante, 5 - January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean - this is less likely to happen. But to be ultra-paranoid, we - do the check anyway.) */ - retVal = MY_STAT ( inName, &statBuf ); - if (retVal == 0) { - if (noisy) - fprintf ( stderr, - "%s: Deleting output file %s, if it exists.\n", - progName, outName ); - if (outputHandleJustInCase != NULL) - fclose ( outputHandleJustInCase ); - retVal = remove ( outName ); - if (retVal != 0) - fprintf ( stderr, - "%s: WARNING: deletion of output file " - "(apparently) failed.\n", - progName ); - } else { - fprintf ( stderr, - "%s: WARNING: deletion of output file suppressed\n", - progName ); - fprintf ( stderr, - "%s: since input file no longer exists. Output file\n", - progName ); - fprintf ( stderr, - "%s: `%s' may be incomplete.\n", - progName, outName ); + /* Check whether input file still exists. Delete output file + only if input exists to avoid loss of data. Joerg Prante, 5 + January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean + this is less likely to happen. But to be ultra-paranoid, we + do the check anyway.) */ + retVal = MY_STAT ( inName, &statBuf ); + if (retVal == 0) { + if (noisy) fprintf ( stderr, - "%s: I suggest doing an integrity test (bzip2 -tv)" - " of it.\n", - progName ); - } + "%s: Deleting output file %s, if it exists.\n", + progName, outName ); + if (outputHandleJustInCase != NULL) + fclose ( outputHandleJustInCase ); + retVal = remove ( outName ); + if (retVal != 0) + fprintf ( stderr, + "%s: WARNING: deletion of output file " + "(apparently) failed.\n", + progName ); + } else { + fprintf ( stderr, + "%s: WARNING: deletion of output file suppressed\n", + progName ); + fprintf ( stderr, + "%s: since input file no longer exists. Output file\n", + progName ); + fprintf ( stderr, + "%s: `%s' may be incomplete.\n", + progName, outName ); + fprintf ( stderr, + "%s: I suggest doing an integrity test (bzip2 -tv)" + " of it.\n", + progName ); + } } if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) { - fprintf ( stderr, - "%s: WARNING: some files have not been processed:\n" - "%s: %d specified on command line, %d not processed yet.\n\n", - progName, progName, - numFileNames, numFileNames - numFilesProcessed ); + fprintf ( stderr, + "%s: WARNING: some files have not been processed:\n" + "%s: %d specified on command line, %d not processed yet.\n\n", + progName, progName, + numFileNames, numFileNames - numFilesProcessed ); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Sat Jun 29 13:45:48 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 15A28550 for ; Sat, 29 Jun 2013 13:45:48 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 079ED16E6 for ; Sat, 29 Jun 2013 13:45:48 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5TDjlcM044823 for ; Sat, 29 Jun 2013 13:45:47 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5TDjlie044820 for svn-soc-all@FreeBSD.org; Sat, 29 Jun 2013 13:45:47 GMT (envelope-from dpl@FreeBSD.org) Date: Sat, 29 Jun 2013 13:45:47 GMT Message-Id: <201306291345.r5TDjlie044820@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253682 - in soc2013/dpl/head: contrib/bzip2 usr.bin/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jun 2013 13:45:48 -0000 Author: dpl Date: Sat Jun 29 13:45:47 2013 New Revision: 253682 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253682 Log: Added debugging printf. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c soc2013/dpl/head/usr.bin/bzip2/Makefile Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 13:33:23 2013 (r253681) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 13:45:47 2013 (r253682) @@ -235,7 +235,7 @@ struct msghdr msg; struct cmsghdr *cmsg; - char buf = { 0 }; + char buf = { "!" }; struct iovec io[1]; io[0].iov_base = buf; @@ -248,11 +248,13 @@ msg.msg_control = cmsg; msg.msg_controllen = CMSG_LEN(sizeof(int)); + printf("About to set CMSG\n"); cmsg->cmsg_len = msg.msg_controllen; cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; + printf("About to set CMSG_DATA as fd\n"); *(int *)CMSG_DATA(cmsg) = fd; - /*Why does sendmsg set errno to 9 EBADF.*/ + printf("CMSG_DATA = fd\n"); if(sendmsg(s, &msg, 0) < 0) return -1; return 0; @@ -261,12 +263,11 @@ int recvfd(int s) { - printf("recvfd on socket:%d\n",s); int fd; struct msghdr msg; struct cmsghdr *cmsg; - char buf = { 0 }; + char buf = { "!" }; struct iovec io[1]; io[0].iov_base = buf; Modified: soc2013/dpl/head/usr.bin/bzip2/Makefile ============================================================================== --- soc2013/dpl/head/usr.bin/bzip2/Makefile Sat Jun 29 13:33:23 2013 (r253681) +++ soc2013/dpl/head/usr.bin/bzip2/Makefile Sat Jun 29 13:45:47 2013 (r253682) @@ -7,6 +7,7 @@ CFLAGS+= -D_FILE_OFFSET_BITS=64 #TODO: Delete this. CFLAGS+= -fno-color-diagnostics +CFLAGS+= -Wall CFLAGS+= -g WARNS?= 3 From owner-svn-soc-all@FreeBSD.ORG Sat Jun 29 19:59:38 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id DDDDCF33 for ; Sat, 29 Jun 2013 19:59:38 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B5960126A for ; Sat, 29 Jun 2013 19:59:38 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5TJxcP9015346 for ; Sat, 29 Jun 2013 19:59:38 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5TJxctg015344 for svn-soc-all@FreeBSD.org; Sat, 29 Jun 2013 19:59:38 GMT (envelope-from dpl@FreeBSD.org) Date: Sat, 29 Jun 2013 19:59:38 GMT Message-Id: <201306291959.r5TJxctg015344@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253695 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jun 2013 19:59:38 -0000 Author: dpl Date: Sat Jun 29 19:59:38 2013 New Revision: 253695 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253695 Log: Resolved a silly bug with pointers. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 18:07:32 2013 (r253694) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 19:59:38 2013 (r253695) @@ -234,7 +234,7 @@ printf("sendfd on socket:%d fd:%d\n",s,fd); struct msghdr msg; - struct cmsghdr *cmsg; + struct cmsghdr cmsg; char buf = { "!" }; struct iovec io[1]; @@ -245,15 +245,15 @@ msg.msg_namelen = 0; msg.msg_iov = io; msg.msg_iovlen = 1; - msg.msg_control = cmsg; + msg.msg_control = &cmsg; msg.msg_controllen = CMSG_LEN(sizeof(int)); printf("About to set CMSG\n"); - cmsg->cmsg_len = msg.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; + cmsg.cmsg_len = msg.msg_controllen; + cmsg.cmsg_level = SOL_SOCKET; + cmsg.cmsg_type = SCM_RIGHTS; printf("About to set CMSG_DATA as fd\n"); - *(int *)CMSG_DATA(cmsg) = fd; + *(int *)CMSG_DATA(&cmsg) = fd; printf("CMSG_DATA = fd\n"); if(sendmsg(s, &msg, 0) < 0) return -1; @@ -266,7 +266,7 @@ int fd; struct msghdr msg; - struct cmsghdr *cmsg; + struct cmsghdr cmsg; char buf = { "!" }; struct iovec io[1]; @@ -277,16 +277,16 @@ msg.msg_namelen = 0; msg.msg_iov = io; msg.msg_iovlen = 1; - msg.msg_control = cmsg; + msg.msg_control = &cmsg; msg.msg_controllen = CMSG_LEN(sizeof(int)); - cmsg->cmsg_len = msg.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - /*Why does sendmsg set errno to 9 EBADF.*/ + cmsg.cmsg_len = msg.msg_controllen; + cmsg.cmsg_level = SOL_SOCKET; + cmsg.cmsg_type = SCM_RIGHTS; + /*Why does sendmsg set errno to 9 EBADF??*/ if(recvmsg(s, &msg, 0) < 0) return -1; - fd = *(int *)CMSG_DATA(cmsg); + fd = *(int *)CMSG_DATA(&cmsg); printf("recvfd() fd recieved: %d", fd); return 0; } From owner-svn-soc-all@FreeBSD.ORG Sat Jun 29 21:38:05 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 59A99C71 for ; Sat, 29 Jun 2013 21:38:05 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 3AB5B170A for ; Sat, 29 Jun 2013 21:38:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5TLc5FR065511 for ; Sat, 29 Jun 2013 21:38:05 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5TLc57n065506 for svn-soc-all@FreeBSD.org; Sat, 29 Jun 2013 21:38:05 GMT (envelope-from dpl@FreeBSD.org) Date: Sat, 29 Jun 2013 21:38:05 GMT Message-Id: <201306292138.r5TLc57n065506@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253699 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jun 2013 21:38:05 -0000 Author: dpl Date: Sat Jun 29 21:38:04 2013 New Revision: 253699 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253699 Log: Minor code changes, still not working. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 20:17:14 2013 (r253698) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Sat Jun 29 21:38:04 2013 (r253699) @@ -231,8 +231,6 @@ int sendfd(int s, int fd) { - printf("sendfd on socket:%d fd:%d\n",s,fd); - struct msghdr msg; struct cmsghdr cmsg; char buf = { "!" }; @@ -248,14 +246,11 @@ msg.msg_control = &cmsg; msg.msg_controllen = CMSG_LEN(sizeof(int)); - printf("About to set CMSG\n"); cmsg.cmsg_len = msg.msg_controllen; cmsg.cmsg_level = SOL_SOCKET; cmsg.cmsg_type = SCM_RIGHTS; - printf("About to set CMSG_DATA as fd\n"); *(int *)CMSG_DATA(&cmsg) = fd; - printf("CMSG_DATA = fd\n"); - if(sendmsg(s, &msg, 0) < 0) + if(sendmsg(s, &msg, 0) <= 0) return -1; return 0; } @@ -263,7 +258,6 @@ int recvfd(int s) { - int fd; struct msghdr msg; struct cmsghdr cmsg; @@ -287,7 +281,7 @@ if(recvmsg(s, &msg, 0) < 0) return -1; fd = *(int *)CMSG_DATA(&cmsg); - printf("recvfd() fd recieved: %d", fd); + printf("recvfd() fd recieved: %d\n", *((int *)CMSG_DATA(&cmsg))); return 0; } #endif @@ -1403,13 +1397,13 @@ exit(exitValue); case ( 0 ): - if ((close(sv[0])) < 0){ + /*if ((close(sv[0])) < 0){ fprintf ( stderr, "%s: Couldn't close socket: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); - } - printf("About to recv infd\n"); + }*/ + printf("About to recv infd\n"); sleep(1); if ((infd = recvfd(sv[1])) < 0){ fprintf ( stderr, "%s: Couldn't get infd: %s.\n", @@ -1459,21 +1453,24 @@ default: printf("Parent: infd:%d, outfd:%d\n", infd, outfd); - if ((close(sv[1])) < 0){ + /*if ((close(sv[1])) < 0){ fprintf ( stderr, "%s: Couldn't close fd: %s.\n", progName, strerror(errno) ); + wait(NULL); setExit(1); exit(exitValue); - } + }*/ if (sendfd(sv[0], infd) < 0){ fprintf ( stderr, "%s: Couldn't send infd: %s.\n", progName, strerror(errno) ); + wait(NULL); setExit(1); exit(exitValue); } if (sendfd(sv[0], outfd) < 0){ fprintf ( stderr, "%s: Couldn't send outfd: %s.\n", progName, strerror(errno) ); + wait(NULL); setExit(1); exit(exitValue); } @@ -2139,6 +2136,7 @@ setExit(1); exit(exitValue); } + printf("socketpair() ended fine: sv[0]:%d sv[1]:%d\n", sv[0], sv[1]); # endif