This paper presents a distributed input rectification methodology to guarantee the safety of a multi-agent system over its pre-given cooperative control task. We start with defining a multi-agent system as a control target, which consists of a group of agents with general control affine nonlinear dynamics and an interconnection topology between agents. The research objective, safety, is next defined via a set invariance property, where a safe set is formed by control barrier functions. Then, an optimization-based distributed safety control method is presented. In the proposed approach, each agent rectifies its control input by solving an individual optimization problem to achieve a pre-given cooperative control strategy as much as possible while satisfying constraints for the safety derived by investigating the control barrier functions. Here, the optimization problem is formulated in a distributed manner by dividing the safety constraint between agents. To show the utility of the present approach, collision avoidance problems of a mobile robotic network are investigated as case studies.