小编Mat*_*ana的帖子

dup2/dup - 为什么我需要复制文件描述符?

我想了解使用dup2dup.

从手册页:

DESCRIPTION

dup and dup2 create a copy of the file descriptor oldfd.
After successful return of dup or dup2, the old and new descriptors may
be used interchangeably. They share locks, file position pointers and
flags; for example, if the file position is modified by using lseek on
one of the descriptors, the position is also changed for the other.

The two descriptors do not share the close-on-exec flag, however.

dup uses the lowest-numbered …
Run Code Online (Sandbox Code Playgroud)

c linux operating-system system-calls

79
推荐指数
2
解决办法
4万
查看次数

实际例子使用dup或dup2

我知道是什么dup/dup2做什么,但我不知道什么时候会被使用.

任何实际的例子?

谢谢.

c unix file system-calls dup

63
推荐指数
4
解决办法
8万
查看次数

我怎么能拦截linux sys调用?

除了LD_PRELOAD技巧,以及用你提供的系统调用取代某个系统调用的Linux内核模块之外,是否有可能拦截一个系统调用(例如打开),以便在它到达实际打开之前首先通过你的函数?

c linux hook redirect system-calls

14
推荐指数
5
解决办法
2万
查看次数

将RGeo列反序列化为SphericalPointImpl

在Rails 4.2.4和activerecord-postgis-adapter 3.1.2中有一个带RGeo列的表

class CreateAddresses < ActiveRecord::Migration
  def change
    create_table :addresses do |t|
      t.st_point :coordinates,   geographic: true, srid: 4326
    end

    add_index :addresses, :coordinates, using: :gist
  end
end
Run Code Online (Sandbox Code Playgroud)

以及按对象位置对对象进行分组的方法

def self.group_by_coords
    includes(:address).
    joins(:address).
    group('addresses.coordinates::geometry').
    pluck(
      'array_agg(realties.id) as ids, addresses.coordinates::geometry'
    )
  end
Run Code Online (Sandbox Code Playgroud)

与相应的测试:

describe 'group_by_coords' do
  it 'correctly group realties' do
    # create samples
    expect(Realty.group_by_coords).to eq(
      [[[r1.id, r2.id], r1.address.coordinates], [[r3.id], r3.address.coordinates]]
    )
  end
end
Run Code Online (Sandbox Code Playgroud)

问题是pluck返回 RGeo::Geos::CAPIPointImpl而不是 RGeo::Geographic::SphericalPointImpl

expected: [[[1670, 1671], #<RGeo::Geographic::SphericalPointImpl:0x3fd37e9b8a20 "POINT (106.0 10.0)">], [[1672], #<RGeo::Geographic::SphericalPointImpl:0x3fd37ab2dddc "POINT (106.5 10.5)">]] …
Run Code Online (Sandbox Code Playgroud)

postgresql activerecord postgis ruby-on-rails-4 rgeo

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

本地窗口上的gitlab-runner错误

我正在尝试本地生成我正在进行的工作hugo网站.它与gitlab CI一起工作正常.

我安装了docker和gitlab runner服务.

然后在这里使用指南,我想我应该这样做gitlab-runner exec docker pages.但结果是:

[0;33mWARNING: Since GitLab Runner 10.0 this command is marked as DEPRECATED and will be removed in one of upcoming releases[0;m
[0KRunning with gitlab-runner 10.5.0 (80b03db9)
[0;m[0KUsing Docker executor with image rocker/tidyverse:latest ...
[0;m[0KPulling docker image rocker/tidyverse:latest ...
[0;m[0KUsing docker image sha256:f9a62417cb9b800a07695f86027801d8dfa34552c621738a80f5fed649c1bc80 for rocker/tidyverse:latest ...
[0;m[31;1mERROR: Job failed (system failure): Error response from daemon: invalid volume specification: '/host_mnt/c/builds/project-0/Users/jan/Desktop/gits/stanstrup-web:C:\Users\jan\Desktop\gits\stanstrup-web:ro'
[0;m[31;1mFATAL: Error response from daemon: …
Run Code Online (Sandbox Code Playgroud)

windows docker hugo gitlab-ci-runner blogdown

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

ptrace(PTRACE_PEEKUSER)和ptrace(PTRACE_PEEKDATA)之间的区别?

在发布了很多问题后ptrace(最近的5个问题是我的:())当我更换时,我终于得到了所需的输出

reg_val[1] = ptrace(PTRACE_PEEKDATA, child, 4 * EBX, NULL);
Run Code Online (Sandbox Code Playgroud)

reg_val[1] = ptrace(PTRACE_PEEKUSER, child, 4 * EBX, NULL);
Run Code Online (Sandbox Code Playgroud)

手册页中提到的差异是这样的

  • PTRACE_PEEKTEXT 在孩子的记忆中的位置addr读取一个单词
  • PTRACE_PEEKUSER 在孩子的USER区域的偏移地址处读取一个单词

我无法从手册页中单独理解这种差异.谁能教育我更多吗?

c ptrace system-calls strace

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

如何检查字符串是否在C中的字符串数组中?

如何用C写下面的代码?另外:是否有内置函数来检查数组的长度?

Python代码

x = ['ab', 'bc' , 'cd']
s = 'ab'

if s in x:
  //Code
Run Code Online (Sandbox Code Playgroud)

c arrays

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

使用ptrace跟踪跨子节点的所有execve()调用

我正在尝试在Linux CentOS上编写一个工具来跟踪所有生成的进程以及运行的内容.本质上,我有兴趣走所有的fork /克隆并从中发出所有的命令行execve().Strace已经(某些)这样做了,但它也截断了调用和参数.我也想更好地了解它是如何ptrace()工作的.

因此,第一个障碍是弄清楚如何使用ptrace()走一个分支/克隆而不需要跟踪程序需要分叉自己的副本.我挖了进来,发现了这个怎么样.由于fork是在Linux上使用clone实现的,所以我注意到strace将一些比特放入克隆系统调用中,以便在没有任何额外麻烦的情况下启用子跟踪.

所以,本质上代码只是一个大问题:

while (1) {
    int pid = wait3(-1,...);

    /* process what happened */

    ptrace(PTRACE_SYSCALL, pid,...);
}
Run Code Online (Sandbox Code Playgroud)

这适用于相对简单的进程/bin/sh,但是,某些进程导致wait()无限期挂起.我唯一能够确定的是,我正在追踪的过程就是sys_rt_sigsuspend()在它的孩子身上执行(因此,追踪者的孙子),然后是楔形物.

我很好奇是否有一种理智的方式可以调试可能发生的事情.有些事情显然阻止了流程树的进展

这是有问题的程序的源代码:

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

/* For the clone flags
 */
#include <sched.h>

/* #include <errno.h> */

#include <sys/ptrace.h>
#include <sys/user.h>

/* Defines our syscalls like 
 */
#include <sys/syscall.h>

#include <sys/reg.h>
#include <stdio.h>

#include <signal.h>

#include <ctype.h>

#include …
Run Code Online (Sandbox Code Playgroud)

linux ptrace system-calls

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

是否可以实现不执行任何系统调用的C程序?

我的老师让我写一个不执行任何系统调用的C函数.函数什么都不做就没有关系.

以下函数是否执行任何系统调用?

int func() {
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果确实如此,你能给我一个像我正在寻找的样本功能吗?

非常感谢.

c unix system-calls

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

从数组中删除前 X 个元素

我有一个名为 arr 的数组,大小为 1024。所以基本上我想删除数组的第 1 个 X 元素。我该怎么做呢?这就是我的想法:创建一个指向数组第一个值的指针(arr[0])。进行指针算术以将其指向数组的第 X 个元素。然后将arr[0]设置为指针p,这将有效地删除前X个元素?这行得通吗?或者有没有更简单的方法来删除数组的前 X 个元素?

c pointers

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