我正在为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创建设备
我想为所有数据库中的所有表创建一个只具有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对所有桌子进行操作.但总是会添加新表.所以这对我来说不是一个可接受的解决方案.有谁知道任何变通方法?
子类"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) 我试图将值插入到包含两个inet类型列的表中.当我尝试向NULL这些列插入值时,我收到错误消息
错误:类型inet的输入语法无效:""
实际上我是使用sqlalchemy从python中做到这一点但我自然会得到同样的错误说:
Session.commit()错误:(DataError)类型inet的输入语法无效:""
我需要能够为这些列添加空值.这些列没有像这样的属性NOT NULL.
我并不熟悉,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) 我有一个用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) 我想观看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
我能做什么?
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)
为什么第一个代码失败了?我错过了什么?
我试图使用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) 我想知道带有三个参数的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) postgresql ×3
c++ ×2
python ×2
bucardo ×1
c ×1
c# ×1
ftp ×1
glassfish ×1
heap ×1
inheritance ×1
java ×1
jdbc ×1
linux ×1
linux-kernel ×1
ls ×1
mknod ×1
notnull ×1
permissions ×1
security ×1
sockets ×1
sqlalchemy ×1
stl ×1
strcpy ×1
struct ×1
subprocess ×1
unix ×1
unix-socket ×1
wireshark ×1