小编Alp*_*gay的帖子

如何从Linux内核模块的init_module代码创建设备节点?

我正在为linux内核编写一个模块,我想在init函数中创建一些设备节点

int init_module(void)
{
    Major = register_chrdev(0, DEVICE_NAME, &fops);
 // Now I want to create device nodes with the returned major number
}
Run Code Online (Sandbox Code Playgroud)

我还希望内核为我的第一个节点分配一个次要编号,然后我将自己分配其他节点的次要编号.

我怎么能在代码中执行此操作.我不想使用mknod从shell创建设备

linux linux-kernel mknod

45
推荐指数
3
解决办法
5万
查看次数

如何在Postgresql中为所有数据库创建具有只读权限的用户?

我想为所有数据库中的所有表创建一个只具有select权限的用户.我以为我可以获取数据库列表并为每个数据库应用以下命令:

GRANT select ON DATABASE dbname to user1;
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

ERROR:  invalid privilege type SELECT for database
Run Code Online (Sandbox Code Playgroud)

当我用谷歌搜索时,人们建议grant select对所有桌子进行操作.但总是会添加新表.所以这对我来说不是一个可接受的解决方案.有谁知道任何变通方法?

security postgresql permissions database-permissions

21
推荐指数
2
解决办法
3万
查看次数

由于构造函数中的"保护级别"错误,C#"无法访问"

子类"caesar"的构造函数给出错误.它说由于其保护级别,名称,类型无法访问.怎么会?因为这是从"Cipher"类派生的子类,所以不应该给出这样的错误.我怎样才能克服这种情况.但我希望这些变量是私有的.我不想将它们改为公开.

***第二个代码示例有效.任何人都能看到差异吗?

namespace Encrypter
{
    class Cipher
    {
        public Cipher(string name, string type)
        {
            setName(name);
            setType(type);

        }
        private string name;
        private string type;

        public void setName(string newName)
        {
            name = newName;
        }
        public string getName()
        {
            return name;
        }
        public void setType(string newType)
        {
            type = newType;
        }
        public string getType()
        {
            return type;
        }
        public string encrypt(string text)
        {
            return text;
        }
        public string decrypt(string text)
        {
            return text;
        }
    }
}




namespace Encrypter
{
    class Caesar : Cipher …
Run Code Online (Sandbox Code Playgroud)

c# inheritance encapsulation access-modifiers

6
推荐指数
3
解决办法
5万
查看次数

将Null值插入postgresql中的inet字段

我试图将值插入到包含两个inet类型列的表中.当我尝试向NULL这些列插入值时,我收到错误消息

错误:类型inet的输入语法无效:""

实际上我是使用sqlalchemy从python中做到这一点但我自然会得到同样的错误说:

Session.commit()错误:(DataError)类型inet的输入语法无效:""

我需要能够为这些列添加空值.这些列没有像这样的属性NOT NULL.

postgresql sqlalchemy notnull

6
推荐指数
1
解决办法
7416
查看次数

glassfish throw org.postgresql.xa.PGXAException

我并不熟悉,J2EE所以在解释错误时我可能会犯一些错误.请多多包涵.

我试图在我的java企业应用程序上运行查询,但glassfish抛出以下异常:

[#|2014-12-05T15:31:00.412+0200|WARNING|glassfishv3.0|javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions|_ThreadID=86;_ThreadName=Thread-1;|JTS5031: Exception [java.lang.RuntimeException: org.postgresql.xa.PGXAException: Error preparing transaction] on Resource [prepare] operation.|#]

[#|2014-12-05T15:31:00.413+0200|SEVERE|glassfishv3.0|javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions|_ThreadID=86;_ThreadName=Thread-1;|JTS5031: Exception [org.omg.CORBA.INTERNAL:   vmcid: 0x0  minor code: 0 completed: Maybe] on Resource [rollback] operation.|#]

[#|2014-12-05T15:31:00.439+0200|WARNING|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=86;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB OFReportTimeoutService method public void com.companyname.appname.service.OFReportTimeoutService.ofTimeout()
javax.ejb.EJBException: Unable to complete container-managed transaction.
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4962)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4716)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1941)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1892)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
    at com.sun.proxy.$Proxy307.ofTimeout(Unknown Source)
    at com.companyname.appname.service.__EJB31_Generated__OFReportTimeoutService__Intf____Bean__.ofTimeout(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.companyname.appname.servlet.GFv3EJBInvokerJob.execute(GFv3EJBInvokerJob.java:88) …
Run Code Online (Sandbox Code Playgroud)

java postgresql jdbc glassfish bucardo

6
推荐指数
1
解决办法
773
查看次数

无法连接到python中的抽象unix套接字

我有一个用c ++编写的服务器,它创建并绑定到名称空间地址为的抽象unix套接字"\0hidden".我也有一个用c ++编写的客户端,这个客户端可以成功连接到我的服务器.顺便说一句,我没有这个客户端的源代码.现在我尝试使用我在python中编写的客户端连接到我的服务器但没有成功.我不明白为什么我的python客户端无法工作.我发布了服务器和客户端代码的相关部分.

服务器

#define UD_SOCKET_PATH          "\0hidden"
struct sockaddr_un addr;
int fd,cl;

if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 
{
    syslog(LOG_CRIT, "Error creating socket!");
    exit(1);
}

memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, UD_SOCKET_PATH, sizeof(addr.sun_path)-1);
unlink(UD_SOCKET_PATH);


if (::bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) 
{
    syslog(LOG_CRIT, "Bind error");
    exit(1);
}

if (listen(fd, MAX_CONN_PENDING) == -1) 
{
    syslog(LOG_CRIT, "Listen error");
    exit(1);
}

syslog(LOG_INFO, "Start listening.");
Run Code Online (Sandbox Code Playgroud)

和我的客户端代码

#! /opt/python/bin/python
import os
import socket
import sys
# Create …
Run Code Online (Sandbox Code Playgroud)

c++ python unix sockets unix-socket

5
推荐指数
1
解决办法
1444
查看次数

使用tshark(wireshark)捕获ftp主机名和uri

我想观看ftp流量并找到使用tshark访问哪些ftp网址.对于我可以使用的http流量

tshark -i eth0 -f 'port 80' -l -t ad -n -R 'http.request' -T fields -e http.host -e http.request.uri
Run Code Online (Sandbox Code Playgroud)

Wireshark的显示过滤器包含字段http.request.uri和http.host请参阅:http://www.wireshark.org/docs/dfref/h/http.html 但这些选项不适用于ftp流量. http://www.wireshark.org/docs/dfref/f/ftp.html

我能做什么?

ftp wireshark

3
推荐指数
1
解决办法
5405
查看次数

在Python subprocess.Popen函数中使用ls

proc = subprocess.Popen(['ls', '-v', self.localDbPath+'labris.urls.*'], stdout=subprocess.PIPE)
while True:
    line = proc.stdout.readline()
    if line != '':
        print line
    else:
        break
Run Code Online (Sandbox Code Playgroud)

使用上面的代码时,我得到错误说:

ls: /var/lib/labrisDB/labris.urls.*: No such file or directory
Run Code Online (Sandbox Code Playgroud)

但是,当我从shell中获取相同内容时,我没有错误:

ls -v /var/lib/labrisDB/labris.urls.*
Run Code Online (Sandbox Code Playgroud)

这也不会给出任何错误:

proc = subprocess.Popen(['ls', '-v', self.localDbPath], stdout=subprocess.PIPE)
while True:
    line = proc.stdout.readline()
    if line != '':
        print line
    else:
        break
Run Code Online (Sandbox Code Playgroud)

为什么第一个代码失败了?我错过了什么?

python subprocess ls

2
推荐指数
1
解决办法
2587
查看次数

无法将字符串复制到结构中的字符串(C)

我试图使用strcpy将一些字符串复制到结构中的字符串.我发布的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct floating_point{
    char sign[2];
    char exponent[9];
    char fraction[24];
}FLOATING_POINT;
FLOATING_POINT stringToFloatingPoint(char* str){
    struct floating_point fp;
    char *integer_str,*fraction_str,*integer_bin,*fraction_bin,*sign;
    sign=(char*)malloc(2*sizeof(char));
    int i=1,integer=0,fraction=0,comma=0,remainder=0,size=0;
    double fraction_double;
    //str=(char*)malloc(200*sizeof(char));
    //str="108,53";
    char * pch=(char*)malloc((strlen(str)+1)*sizeof(char));
    pch=strchr(str,',');
    if(pch==NULL){
        pch=str+strlen(str);
    }
    comma=pch-str;
    integer_str=(char*)malloc((comma+1)*sizeof(char));
    strncpy(integer_str,str,comma);
    integer_str[comma]='\0',
    integer=atoi(integer_str);
    fraction_str=(char*)malloc((strlen(str)-comma+2)*sizeof(char));
    strncpy(fraction_str,str+comma+1,strlen(str)-1);
    fraction_str[strlen(str)-comma]='\0';
    fraction=atoi(fraction_str);
    printf("%d",fraction);
    printf("%s",fraction_str);
    if(integer<0){
        strcpy(sign,"1");
        integer=-1*integer;
    }
    else{
        strcpy(sign,"0");
    }
    size=(int)(log(integer)/log(2))+2;
    integer_bin=(char*)malloc(size*sizeof(char));
    while(integer>0){
        remainder=fmod(integer,2);
        integer=integer/2;
        *(integer_bin+size-i-1)=(char)(remainder+48);
        i++;
    }
    *(integer_bin+size-i-1)=(char)(integer+48);
    *(integer_bin+size-1)='\0';
    printf("%s\n",integer_bin);
    fraction_bin=(char*)malloc(24*sizeof(char));
    fraction_double=atof(fraction_str);
    fraction_double=fraction_double/(pow(10,strlen(fraction_str)));
    printf("frac= %f",fraction_double);
    i=0;
    while((i<23)&&fraction_double!=0){
        fraction_double=2*fraction_double;
        if(fraction_double<1){
            *(fraction_bin+i)='0'; …
Run Code Online (Sandbox Code Playgroud)

c struct strcpy

1
推荐指数
1
解决办法
1255
查看次数

C++中的push_heap函数有什么作用?

我想知道带有三个参数的push_heap函数是做什么的?

#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

class HeapCompare_f
    {
        public:

            bool operator() ( int x, int y ) const
            {
                return x > y;
            }
    };
int main()
{
    vector<int> vector1(5);

    for (int i = 0; i < 5; ++i)
        vector1[i] = 5-i;

    for (int i = 0; i < 5; ++i)
        cout << vector1[i];
    cout << endl;

    push_heap(vector1.begin(), vector1.end(),HeapCompare_f());

    for (int i = 0; i < 5; ++i)
        cout << vector1[i];
    cout << …
Run Code Online (Sandbox Code Playgroud)

c++ heap stl

1
推荐指数
2
解决办法
6040
查看次数